使用Python的Google API自定义搜索-程序化搜索结果 [英] Google API Custom Search with Python - Programmatic Search Results
问题描述
我正在尝试使用Google API自定义搜索,但是我不知道从哪里开始.似乎您必须创建一个自定义搜索引擎"才能解析搜索结果,并且每天最多只能使用100个.
I am trying to use the Google API Custom Search, and I don't have any clue where to start. It seems you have to create a "custom search engine" in order to parse search results, and you are limited to 100 per day.
我应该为此使用哪个模块?我相信我从这里开始: http://code.google.com/p/google-api-python-client/
What module should I use for this? I believe I start here: http://code.google.com/p/google-api-python-client/
我需要API密钥之类的东西吗?基本上,我希望能够执行此操作,并且Google的文档令人困惑,甚至超出了我的水平.
I need an API key or something? Basically I want to be able to do this operation, and Google's documentation is confusing, or perhaps beyond my level.
伪代码:
from AwesomeGoogleModule import GoogleSearch
search = GoogleSearch("search term")
results = search.SearchResultsNumber
print results
基本上,您得到的特定搜索词的总结果数是多少?我要刮.我不想通过前端Google,因为这很容易被阻止.我不需要超出API允许的100个搜索范围.仅适用于30-50个搜索字词,可能是MOST的80-100个搜索字词.
Basically, that number you get of total results for a particular search term? I want to scrape it. I don't want to go via the front-end Google, because that's very easy to get blocked. I don't need to go beyond the 100 searches that the API allows. This will only be for 30-50 search terms, maybe 80-100 at MOST.
推荐答案
使用google-api-python-client库进行自定义搜索的示例代码在这里:
Sample code for Custom Search using the google-api-python-client library is here:
http://code .google.com/p/google-api-python-client/source/browse/#hg%2Fsamples%2Fcustomsearch
您将需要访问以下内容来创建自己的API密钥:
You will need to create your own API Key by visiting:
https://code.google.com/apis/console/
在API控制台中创建一个项目,确保打开该项目的自定义搜索API",然后您会在"API访问"标签的底部找到API密钥.
Create a project in the APIs Console, making sure to turn on the Custom Search API for that project, and then you will find the API Key at the bottom of the API Access tab.
这篇关于使用Python的Google API自定义搜索-程序化搜索结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!