【问题标题】:Query Limits with Python's Google Module使用 Python 的 Google 模块进行查询限制
【发布时间】:2017-07-26 07:19:23
【问题描述】:

我从电子表格中提取了大约 100,00 个值并获取第一个结果以查看它们是 http 还是 https。脚本工作正常(对我的目的来说足够好),但在循环的第 70 次迭代后出现 503 错误。

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

代码:

import pandas as pd
import re
import time
library_list = pd.read_csv("PLS_FY2014_AE_pupld14a.csv")

zero = 0
with_https = 0 

for i in library_list['LIBNAME']:
    for url in search(library_list['LIBNAME'][zero], num = 1, start = 0, stop = 1):
        time.sleep(5)
        zero += 1
        print(zero)
        if 'https' in url:
            with_https += 1

【问题讨论】:

标签: python python-2.7 google-search


【解决方案1】:

我正在尝试做同样的事情,但在 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 天,没有更多错误。它可能很慢,但最终它会完成工作。这一轮我用它进行了大约 18,000 次搜索。

【讨论】:

  • 谢谢!这也证实了我的想法。好想我下周要放假,我走的时候就让它跑吧。
猜你喜欢
  • 2012-05-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-07-07
  • 1970-01-01
  • 2018-01-08
  • 2019-07-17
  • 1970-01-01
相关资源
最近更新 更多