diffbot api的python客户端。
diffbot的Python项目详细描述
使用方法:
>>>importdiffbot>>>json_result=diffbot.article('https://github.com',token='…')
上面的简单示例是使用^{tt1}的快捷方式$ 上课
>>>importdiffbot>>>client=diffbot.Client(token='…')>>>json_result=client.article('https://github.com')
以上调用是使用diffbot.api()函数的快捷方式 以及diffbot.Client.api方法:
>>>importdiffbot>>>client=diffbot.Client(token='…')>>>json_result=client.api('article','https://github.com')
要将POST数据(文本或HTML)发送到API,请使用text或html 参数:
>>>importdiffbot>>>client=diffbot.Client(token='…')>>>json_result=client.api('article','https://github.com',html=''' ... <h1>Introducing GitHub Traffic Analytics</h1> ... <p>We want to kick off 2014 with a bang, so today we're happy to launch ... traffic analytics!</p> ... ''')
命令行界面:
$ python diffbot.py -h usage: diffbot.py [-h][-a][-f FILE] api url token positional arguments: api API to call. One one of 'article', 'frontpage', 'product', 'image', 'analyze' or 'discussion'. url URL to pass as the 'url' parameter. token API key (token). Get one at https://www.diffbot.com/. optional arguments: -h, --help show this help message and exit -a, --all Request all fields. -f FILE, --file FILE File to read data from. Use '-' to read from STDIN. $ python diffbot.py article https://github.com TOKEN
上述示例的输出:
{"icon":"https://github.com:443/apple-touch-icon-144.png","sections":[…],"title":"Build software better, together.","url":"https://github.com/"}
特点:
- Python 2+3支持
- 谷歌应用引擎支持
- Requests支持(但不依赖)
- 通过pyflakes,pep8,flake8,pylint得分10/10
- 简单小(1个文件,<;200个位置)
- 命令行界面