跳转到主要内容

Diffbot API的Python客户端。

项目描述

Bitdeli Build Status Coverage Status

如何使用它

>>> import diffbot
>>> json_result = diffbot.article('https://github.com', token='…')

上面的简单示例是使用diffbot.Client类的快捷方式。

>>> import diffbot
>>> client = diffbot.Client(token='…')
>>> json_result = client.article('https://github.com')

上面的调用是使用diffbot.api()函数和diffbot.Client.api方法的快捷方式

>>> import diffbot
>>> client = diffbot.Client(token='…')
>>> json_result = client.api('article', 'https://github.com')

要将数据(文本或HTML)POST到API,请使用texthtml参数

>>> import diffbot
>>> 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支持

  • Google App Engine支持

  • Requests支持(但无依赖项)

  • 通过pyflakespep8flake8pylint评分10/10

  • 简单 & 小型(1文件,<200LOC)

  • 命令行界面

项目详情


下载文件

下载您平台的文件。如果您不确定选择哪个,请了解更多关于 安装包 的信息。

源分布

diffbot-2.0.0.tar.gz (5.1 kB 查看哈希值)

上传时间

由以下支持