用于python的kltool、用于web的toolset、http、cache、dht、xml、json等
pykl的Python项目详细描述
pykl是用于python的kltool,用于web、http、cache、dht、xml、json等的工具集。
在您的控制台中键入安装:
pip install pykl
用法
您可以执行pykl --test来启动测试服务器进行测试 查询或
pykl QUERY_FILE
此命令将写入标准输出(或其他输出,如果 通过--output指定生成的json。
您的QUERY_FILE看起来可能类似于这样:
{ page(url:"http://news.ycombinator.com") { items: query(selector:"tr.athing") { rank: text(selector:"td span.rank") title: text(selector:"td.title a") sitebit: text(selector:"span.comhead a") url: attr(selector:"td.title a", name:"href") attrs: next { score: text(selector:"span.score") user: text(selector:"a:eq(0)") comments: text(selector:"a:eq(2)") } } } }
高级用法
如果要将pykl查询泛化到任何页面,只需重写 添加$pagevar的查询文件。 这个:
query ($page: String) { page(url:$page) { # ... } }
然后,像这样查询:
pykl QUERY_FILE http://news.ycombinator.com