使用Python查询限制';谷歌模块

使用Python查询限制';谷歌模块,python,python-2.7,google-search,Python,Python 2.7,Google Search,我正在从电子表格中提取大约100,00个值,并获取第一个结果,看看它们是http还是https。这些脚本工作得很好(对于我来说已经足够好了),但是在循环的第70次迭代之后,我得到了一个503错误 关于如何获得我需要的查询量,有什么想法/想法/建议吗 代码: 我正在尝试做同样的事情,在30-50个结果之后,我得到了503错误。我最终迫使搜索在每次搜索中随机等待30到60秒。我读到其他人也有同样的问题,他们说谷歌将机器人搜索限制在每小时50次左右。我使用的代码是 import os, arcpy,

我正在从电子表格中提取大约100,00个值,并获取第一个结果,看看它们是http还是https。这些脚本工作得很好(对于我来说已经足够好了),但是在循环的第70次迭代之后,我得到了一个503错误

关于如何获得我需要的查询量,有什么想法/想法/建议吗

代码:


我正在尝试做同样的事情,在30-50个结果之后,我得到了503错误。我最终迫使搜索在每次搜索中随机等待30到60秒。我读到其他人也有同样的问题,他们说谷歌将机器人搜索限制在每小时50次左右。我使用的代码是

import os, arcpy, urllib, ssl, time, datetime, random, errno
from datetime import datetime
from arcpy import env
from distutils.dir_util import copy_tree
try:
    from google import search
except ImportError:
    print("No module named 'google' found")
from google import search
with arcpy.da.UpdateCursor(facilities, ["NAME", "Weblinks", "ADDRESSSTATECODE", "MP_TYPE"]) as rows:
    for row in rows:
        if row[1] is None:
            if row[3] != "xxxxxx":
                query = str(row[0])
                print("The query will be " + query)
                wt = random.uniform(30,60)
                print("Script will wait " + str(wt) + " seconds before the next search.")
                for j in search("recreation.gov " + query + ", " + str(row[2]), tld="co.in", num=1, stop=1, pause=wt):
                    row[1] = str(j)
                    rows.updateRow(row)
                    print(row[1])
                    time.sleep(5)
                    print("")

我的脚本已经连续运行了7天,没有任何错误。它可能很慢,但最终会完成任务。这一轮我用它进行了大约18000次搜索。

可能与此谷歌搜索帮助相关的信息回答是的,我最好的解决方案是将时间.sleep()增加到20秒左右,但这使得搜索速度非常缓慢。我希望有人已经找到了一种方法来创建不会被阻止或违反ToS的脚本。当您出现503错误时,您是否检查了“错误页面很可能显示验证码”是否可以进行身份验证,并允许脚本继续?嗯,好的,在
search
函数中还有一个
pause
参数(例如`search(查询,tld='com',lang='en',num=10,start=0,stop=None,pause=2.0)`这可能对暂停有帮助,也可能没有帮助,但要小心,因为文档上说的听起来不错,报告任何进展,祝你好运!这也证实了我的想法。很好,我想我下周休假,我会在我不在的时候让它运行。
import os, arcpy, urllib, ssl, time, datetime, random, errno
from datetime import datetime
from arcpy import env
from distutils.dir_util import copy_tree
try:
    from google import search
except ImportError:
    print("No module named 'google' found")
from google import search
with arcpy.da.UpdateCursor(facilities, ["NAME", "Weblinks", "ADDRESSSTATECODE", "MP_TYPE"]) as rows:
    for row in rows:
        if row[1] is None:
            if row[3] != "xxxxxx":
                query = str(row[0])
                print("The query will be " + query)
                wt = random.uniform(30,60)
                print("Script will wait " + str(wt) + " seconds before the next search.")
                for j in search("recreation.gov " + query + ", " + str(row[2]), tld="co.in", num=1, stop=1, pause=wt):
                    row[1] = str(j)
                    rows.updateRow(row)
                    print(row[1])
                    time.sleep(5)
                    print("")