跳转到主要内容

webz.io REST API的简单客户端库

项目描述

从您的Python代码访问Webz.io API的简单方法:: .. code-block:: python

import webzio

webzio.config(token=YOUR_API_KEY) output = webzio.query(“filterWebContent”, {“q”:”github”}) print output[‘posts’][0][‘text’] # 打印第一条帖子的文本 print output[‘posts’][0][‘published’] # 打印第一条帖子的发布日期

# 获取下一批帖子 output = webzio.get_next() print output[‘posts’][0][‘thread’][‘site’] # 打印第一条帖子的站点

API密钥

为了使用webz.io API,您需要获取一个用于每个请求的令牌。要获取API密钥,请创建https://webz.io/auth/signup的账户,然后进入https://webz.io/dashboard查看您的令牌。

安装

您可以从源安装

$ git clone https://github.com/webz.io/webzio-python
$ cd webzio-python
$ python setup.py install

或使用pip install

$ sudo pip install webzio

使用API

要开始,您需要导入库并设置访问令牌。(将YOUR_API_KEY替换为您的实际API密钥)。

>>> import webzio
>>> webzio.config(token=YOUR_API_KEY)

API端点

查询()函数接受的第一个参数是API端点字符串。可用端点:* filterWebContent - 访问新闻/博客/论坛/评论API

现在您可以发出请求并检查结果

>>> output = webzio.query("filterWebContent", {"q":"github"})
>>> output['totalResults']
15565094
len(output['posts'])
100
>>> output['posts'][0]['language']
u'english'
>>> output['posts'][0]['title']
u'Putting quotes around dictionary keys in JS'

为了方便起见,输出对象是可迭代的,因此您可以遍历它并获取这批的所有结果(最多100个)。

>>> total_words = 0
>>> for post in output['posts']:
...     total_words += len(post['text'].split(" "))
...
>>> print(total_words)
8822

完整文档

  • config(token)

    • token - 您的API密钥

  • query(end_point_str, params)

    • end_point_str: * filterWebContent - 访问新闻/博客/论坛/评论API

    • params: 键值字典。最常见的键是“q”参数,它包含布尔查询的过滤器。[关于可用过滤器的更多信息](https://webz.io/documentation).

  • get_next() - 获取下一页结果的函数。

轮询

如果您想进行重复搜索,每当有新结果时执行操作,请使用如下代码

r = webzio.query("filterWebContent", {"q":"skyrim"})
while True:
    for post in r['posts']:
        perform_action(post)
    time.sleep(300)
    r = webzio.get_next()

项目详情


下载文件

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

源代码发行版

webzio-1.0.2.tar.gz (4.0 kB 查看哈希值)

上传时间 源代码

支持者