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 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 2f04af2bdf3b570458c75182c56ff624a22c951ccf176c732392c58576f1ddd0 |
|
MD5 | ea57c3c85a017552e2f0d051edd32722 |
|
BLAKE2b-256 | 8b7395981b779d4cf1677443fc97e106a4a96faa97364967e33f2f81961ffccd |