如何检查url是否由google使用google自定义搜索API和Python编制索引?

如何检查url是否由google使用google自定义搜索API和Python编制索引?,python,url,search,google-custom-search,indexed,Python,Url,Search,Google Custom Search,Indexed,我需要检查谷歌是否使用python脚本和谷歌自定义搜索为一些URL编制了索引。 我希望在脚本中获得与我在浏览器中搜索网站www.example.it时相同的结果。 我的代码是: import urllib2 import json import pprint data = urllib2.urlopen('https://www.googleapis.com/customsearch/v1?key=AIzaSyA3xNw1doOc4rjoUGc7sq1gltQvOgalHqA&cx=01

我需要检查谷歌是否使用python脚本和谷歌自定义搜索为一些URL编制了索引。 我希望在脚本中获得与我在浏览器中搜索网站www.example.it时相同的结果。 我的代码是:

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'}}
正如你们看到的那个样,若你们在谷歌上搜索这个网站,并没有“项目”:你们至少有一个项目

经过各种实验,谷歌定制搜索似乎不适用于查询站点:网站

你知道这个问题的解决方案或替代方案吗?
谢谢。

使用Google CSE,您可以通过CSE配置(对应于“cx”参数)而不是通过“site:”查询参数指定站点。在CSE的“基础”选项卡中,您应该看到一个名为“要搜索的站点”的部分。

URL位于Excel文件中

import requests
import pandas as pd
import time
from bs4 import BeautifulSoup
from urllib.parse import urlencode

seconds = 3
proxies = {
    'https' : 'https://localhost:8123',
    'http' : 'http://localhost:8123'
    }

user_agent = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36'
headers = { 'User-Agent' : user_agent}

df = pd.read_excel('url_links.xlsx')
for i in range(0, len(df)):
    line = df.loc[i,'links']
    #print(line)
    if line:
        query = {'q': 'site:' + line}
        google = "https://www.google.com/search?" + urlencode(query)
        data = requests.get(google, headers=headers)
        data.encoding = 'ISO-8859-1'
        soup = BeautifulSoup(str(data.content), "html.parser")
        try:
            check = soup.find(id="rso").find("div").find("div").find("div").find("div").find("div").find("a")["href"]
            print("URL is Index ")
        except AttributeError:
            print("URL Not Index")
        time.sleep(float(seconds))
    else:
        print("Invalid Url")