繁体   English   中英

如何从谷歌使用python获得最后2小时的结果?

[英]How get result of last 2 hour from google using python?

我有一个搜索主题“leo messi”。 我想在过去2小时内发布关于“leo messi”的所有博客。 现在我被困在这里。这段代码没有过滤博客和时间

import urllib
import json as m_json
query = "leo messi"
query = urllib.urlencode ( { 'q' : query } )
response = urllib.urlopen ( 'http://ajax.googleapis.com/ajax/services/search/web?v=1.0&' + query ).read()
json = m_json.loads ( response )
results = json [ 'responseData' ] [ 'results' ]
for result in results:
    title = result['title']
    url = result['url']   # was URL in the original and that threw a name error exception
    print ( title + '; ' + url )

根据此文档, google API仅提供dateRestrict参数,允许您添加这些限制:

根据日期将结果限制为URL。 支持的值包括:

  • d [number]:请求指定过去天数的结果。
  • w [number]:请求指定过去几周的结果。
  • m [number]:请求指定过去几个月的结果。
  • y [number]:请求指定过去年份的结果。

虽然经过更详细的搜索后我发现显示了tbs=qdr参数,可以按照以下方式使用:

您可以指定不同的时间段

  • tbs = qdr:s - 前一秒
  • tbs = qdr:n - 前一分钟
  • tbs = qdr:h - 前一个小时
  • tbs = qdr:d - 前一天
  • tbs = qdr:w - 上周
  • tbs = qdr:m - 上个月
  • tbs = qdr:y - 去年

但我不知道它是否适用于websearch api。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM