2014-04-07 59 views
0

我需要检查一些网址是否由谷歌使用python脚本和谷歌自定义搜索索引。 我想在脚本中获得同样的结果,当我从我的浏览器中获得我谷歌网站:www.example.it。 我的代码是:如何检查谷歌使用谷歌自定义搜索API和Python是否索引一个网址?

import urllib2 
import json 
import pprint 
data = urllib2.urlopen('https://www.googleapis.com/customsearch/v1?key=AIzaSyA3xNw1doOc4rjoUGc7sq1gltQvOgalHqA&cx=017576662512468239146:omuauf_lfve&q=site:http://www.repubblica.it/politica/2014/04/07/news/governo_e_patto_su_italicum_brunetta_a_renzi_riforma_elettorale_entro_pasqua_o_si_dimetta-82947958/?ref=HREA-1') 
data=json.load(data) 
print data 

的这个输出是:

{ u'kind': u'customsearch#search', 
u'queries': { u'request': [ { u'count': 10, 
            u'cx': u'017576662512468239146:omuauf_lfve', 
            u'inputEncoding': u'utf8', 
            u'outputEncoding': u'utf8', 
            u'safe': u'off', 
            u'searchTerms': u'site:http://www.repubblica.it/politica/2014/04/07/news/governo_e_patto_su_italicum_brunetta_a_renzi_riforma_elettorale_entro_pasqua_o_si_dimetta-82947958/?ref=HREA-1', 
            u'title': u'Google Custom Search - site:http://www.repubblica.it/politica/2014/04/07/news/governo_e_patto_su_italicum_brunetta_a_renzi_riforma_elettorale_entro_pasqua_o_si_dimetta-82947958/?ref=HREA-1', 
            u'totalResults': u'0'}]}, 
u'searchInformation': { u'formattedSearchTime': u'0.55', 
          u'formattedTotalResults': u'0', 
          u'searchTime': 0.552849, 
          u'totalResults': u'0'}, 
u'url': { u'template': u'https://www.googleapis.com/customsearch/v1?q={searchTerms}&num={count?}&start={startIndex?}&lr={language?}&safe={safe?}&cx={cx?}&cref={cref?}&sort={sort?}&filter={filter?}&gl={gl?}&cr={cr?}&googlehost={googleHost?}&c2coff={disableCnTwTranslation?}&hq={hq?}&hl={hl?}&siteSearch={siteSearch?}&siteSearchFilter={siteSearchFilter?}&exactTerms={exactTerms?}&excludeTerms={excludeTerms?}&linkSite={linkSite?}&orTerms={orTerms?}&relatedSite={relatedSite?}&dateRestrict={dateRestrict?}&lowRange={lowRange?}&highRange={highRange?}&searchType={searchType}&fileType={fileType?}&rights={rights?}&imgSize={imgSize?}&imgType={imgType?}&imgColorType={imgColorType?}&imgDominantColor={imgDominantColor?}&alt=json', 
      u'type': u'application/json'}} 

正如你可以看到有没有“物品”,如果你谷歌网站的同时:http://www.repubblica.it/politica/2014/04/07/news/governo_e_patto_su_italicum_brunetta_a_renzi_riforma_elettorale_entro_pasqua_o_si_dimetta-82947958/?ref=HREA-1你至少有一个项目。

各种实验之后,似乎谷歌定制搜索不适用于查询网站工作:网站。

您是否知道此问题的任何解决方案或替代方案? 谢谢。

回答

0

与谷歌CSE您通过指定自定义搜索引擎配置的站点(对应于您的“CX”参数)通过“网站:”没有查询参数。在CSE的“基础”选项卡中,您应该看到一个名为“要搜索的网站”的部分。