Google 本地搜索 API + Python
我正在尝试创建一个程序(用Python),它将输出查询Google的本地搜索并将结果打印到控制台。我希望能够搜索“伦敦咖啡馆”并在屏幕上显示公司名称、地址和电话号码。 我在以下位置找到了一个易于使用的 Google 地图和本地搜索 API 的 Python 包装器:
http://py-googlemaps.sourceforge.net/#googlemaps-methods
包装器本质上以 JSON 格式返回数据,但它似乎只返回可用的数千个结果中的 32 个。我的问题是如何访问更多?
该代码执行类似以下操作:
url = query_url + encoded_params
request = urllib2.Request(url, headers=headers)
response = urllib2.urlopen(request)
return (url, json.load(response))
这会生成 urls:
/local?q=cafe+near+London&start=0&rsz=large&v=1.0
/local?q=cafe+near+London&start=8&rsz=large&v=1.0
/local?q=cafe+near+London&start=16&rsz=large&v=1.0
/local?q=cafe+near+London&start=24&rsz=large&v=1.0
.. 和 JSON 格式的数据 url 中的差异是“start=”值增加 8。但是,当替换 start= 32 时,我收到错误。结果的最大数量似乎被锁定为总共 32 个。我怎样才能超越这个范围?
预先感谢您的所有帮助
I am trying to crate a program (in python) that will output query Google’s Local Search and print results to the console. I want to be able to search for “café in London” and get the company names addresses and phone number printed on screen.
I found an easy-to-use Python wrapper for the Google Maps and Local Search APIs on available at:
http://py-googlemaps.sourceforge.net/#googlemaps-methods
The wrapper essentialy returns data in JSON format but it only seems to return 32 results out of the available thousands. My question is how do I access more?
The code does something like this:
url = query_url + encoded_params
request = urllib2.Request(url, headers=headers)
response = urllib2.urlopen(request)
return (url, json.load(response))
That results in urls:
/local?q=cafe+near+London&start=0&rsz=large&v=1.0
/local?q=cafe+near+London&start=8&rsz=large&v=1.0
/local?q=cafe+near+London&start=16&rsz=large&v=1.0
/local?q=cafe+near+London&start=24&rsz=large&v=1.0
..and JSON formated data
The difference in the urls is the 'start=' value that increments by 8. However when substituting start= 32 I get an error. The maximum number of results seems locked at 32 in total. How do I go beyond that?
Thanks in advance for all your help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Google 只允许 4 页上有 32 个内容。您获得的 URL 用于分页。检查此链接
http://code.google.com/apis/maps/ Documentation/localsearch/devguide.html
和搜索
使用 ctrl-F 在该页面上“没有办法获得更多”
Google allows only 32 on 4 pages. The URLs you get are for pagination. Check this link
http://code.google.com/apis/maps/documentation/localsearch/devguide.html
and search
"There is no way to get more than" on that page using ctrl-F
您确定您对 Google API 的使用符合 TOS 吗?我不是律师,但我记得不允许保存或重复使用结果。
话虽如此,还有另一种方法。你可以直接从屏幕上抓取结果。并不是说我当然会推荐这样的非法活动。
这样您就可以使用像这样的 url 来查看结果:
等等。
在任何情况下,结果数量都限制为 160。
Are you sure your use of the Google API complies with the TOS? Im no lawyer but I recall that saving or re-using the results was not allowed.
Having said that, there is another approach. you could just screen scrape the results. not that I would of course recommend such an Illegal activity.
That way you could go over the results using the url like this:
etc.
In any case the results number is limited to 160 this way.