webhose.io rest api的简单客户端库
webhoseio的Python项目详细描述
用于python的webhose.io客户机
==
一种从python代码访问[webhose.io](https://webhose.io)api的简单方法
``python
import webhoseio
webhoseio.config(token=your_api_key)
output=webhoseio.query(“filterWebData”,{“q”:“github”})
打印输出['posts'][0]['text']\第一个post
```
----
要使用webhose.io api,您需要获得一个令牌,该令牌将在每次请求时使用。要获取API密钥,请在
https://webhose.io/auth/signup创建一个帐户,然后进入
https://webhose.io/dashboard查看您的令牌。
``` bash
$sudo pip install webhoseio
```
使用api
----
要开始,您需要导入库并设置访问令牌。
(用实际的api密钥替换您的api密钥)。
``python
>;import webhoseio
>;webhoseio.config(token=您的api密钥)
```
**api端点**
query()函数接受的第一个参数是api端点字符串。可用的终结点:
*FilterWebData-访问新闻/博客/论坛/评论API
*ProductSearch-访问有关电子商务产品/服务的数据
*DarkWebAPI-访问黑暗网络(即将到来)
现在您可以提出请求并检查结果:
``python
>;output=webhoseio.query(“filterWebData”,{“q”:“github”})
>;>output['totalresults']
15565094
len(output['posts'])
100
>;>output['posts'][0]['language']
u'english'
>;>output['posts'][0]['title']
u'puting quotes around dictionary keys in js'
```
>为方便起见,ouut对象是iterable的,因此您可以循环它
,并获得该批的所有结果(最多100个)。
`` python
>;>;总字数=0
>;>;对于post-in-output['posts']:
…总字数+=len(post['text'].split(“”)
…
>;>;打印(总字数)
8822
````
params)``
*端点str:
*filterWebData-访问新闻/博客/论坛/评论API
*productSearch-访问有关电子商务产品/服务的数据
*darkWebAPI-访问黑暗网络(即将推出)
*params:一个关键值字典。最常见的键是保存过滤器布尔查询的“q”参数。[了解可用的筛选器](https://webhose.io/documentation)。
*``get_next()``-获取下一页结果的方法。
polling
----
如果要重复搜索,请在有新结果时执行操作,使用这样的代码:
`` python
r=webhoseio.query(“filterWebData”,{“q”:“skyrim”})
如果为true:
对于r['posts']中的post:
执行操作(post)
时间。睡眠(300)
r=webhoseio.get_next()
````
==
一种从python代码访问[webhose.io](https://webhose.io)api的简单方法
``python
import webhoseio
webhoseio.config(token=your_api_key)
output=webhoseio.query(“filterWebData”,{“q”:“github”})
打印输出['posts'][0]['text']\第一个post
```
要使用webhose.io api,您需要获得一个令牌,该令牌将在每次请求时使用。要获取API密钥,请在
https://webhose.io/auth/signup创建一个帐户,然后进入
https://webhose.io/dashboard查看您的令牌。
``` bash
$sudo pip install webhoseio
```
使用api
----
要开始,您需要导入库并设置访问令牌。
(用实际的api密钥替换您的api密钥)。
``python
>;import webhoseio
>;webhoseio.config(token=您的api密钥)
```
**api端点**
query()函数接受的第一个参数是api端点字符串。可用的终结点:
*FilterWebData-访问新闻/博客/论坛/评论API
*ProductSearch-访问有关电子商务产品/服务的数据
*DarkWebAPI-访问黑暗网络(即将到来)
现在您可以提出请求并检查结果:
``python
>;output=webhoseio.query(“filterWebData”,{“q”:“github”})
>;>output['totalresults']
15565094
len(output['posts'])
100
>;>output['posts'][0]['language']
u'english'
>;>output['posts'][0]['title']
u'puting quotes around dictionary keys in js'
```
>为方便起见,ouut对象是iterable的,因此您可以循环它
,并获得该批的所有结果(最多100个)。
`` python
>;>;总字数=0
>;>;对于post-in-output['posts']:
…总字数+=len(post['text'].split(“”)
…
>;>;打印(总字数)
8822
````
params)``
*端点str:
*filterWebData-访问新闻/博客/论坛/评论API
*productSearch-访问有关电子商务产品/服务的数据
*darkWebAPI-访问黑暗网络(即将推出)
*params:一个关键值字典。最常见的键是保存过滤器布尔查询的“q”参数。[了解可用的筛选器](https://webhose.io/documentation)。
*``get_next()``-获取下一页结果的方法。
polling
----
如果要重复搜索,请在有新结果时执行操作,使用这样的代码:
`` python
r=webhoseio.query(“filterWebData”,{“q”:“skyrim”})
如果为true:
对于r['posts']中的post:
执行操作(post)
时间。睡眠(300)
r=webhoseio.get_next()
````