Skip to main content

Diffbot API 的 Python 客户端。

项目描述

比特德里 构建状态 覆盖状态

如何使用它:

>>> 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)发布到 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 支持

  • 谷歌应用引擎支持

  • 请求支持(但不依赖)

  • 通过pyflakespep8flake8pylint分数 10/10

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

  • 命令行界面

下载文件

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

源分布

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

已上传 source