为什么通过 simplejson 的 Google API 查询返回“responseData”:null?
我正在尝试使用 Python 和 simplejson 截屏 Google 搜索的第一个结果,但我无法像许多在线示例演示的那样访问搜索结果。这是一个片段:
url = 'http://ajax.googleapis.com/ajax/services/search/web?v=1.0&%s' % (query)
search_results = urllib.urlopen(url)
json = simplejson.load(search_results)
try:
results = json['responseData']['results'] # always fails at this line
first_result = results[0]
except:
print "attempt to set results failed"
当我访问 http://ajax在浏览器中访问 .googleapis.com/ajax/services/search/web?v=1.0&stackoverflow(或任何其他替代 %s 的内容),它会显示行 "{"responseData": null, " responseDetails": "剪辑扫描", "responseStatus": 204}。"除了尝试使用明显空的responseData之外,还有其他方法可以在Python中访问Google搜索的结果吗?
I'm trying to screenscrape the first result of a Google search using Python and simplejson, but I can't access the search results the way that many examples online demonstrate. Here's a snippet:
url = 'http://ajax.googleapis.com/ajax/services/search/web?v=1.0&%s' % (query)
search_results = urllib.urlopen(url)
json = simplejson.load(search_results)
try:
results = json['responseData']['results'] # always fails at this line
first_result = results[0]
except:
print "attempt to set results failed"
When I go to http://ajax.googleapis.com/ajax/services/search/web?v=1.0&stackoverflow (or anything else substituted for the %s) in a browser, it displays the line "{"responseData": null, "responseDetails": "clip sweeping", "responseStatus": 204}." Is there some other way to access the results of a Google search in Python besides trying to use the apparently empty responseData?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您错过了 &q=。您还应该考虑使用 api-key。 http://code.google.com/intl/de/apis/ajaxsearch /文档/。除了纯字符串接触不起作用之外,您还需要转义参数。
You missed the &q=. You also should consider using an api-key. http://code.google.com/intl/de/apis/ajaxsearch/documentation/. Besides that plain string contaction wont work, you need to escape the parameter.