gpt4 book ai didi

python - Python 的 Google 模块的查询限制

转载 作者:太空宇宙 更新时间:2023-11-03 10:54:11 24 4
gpt4 key购买 nike

我从电子表格中提取大约 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

最佳答案

我正在尝试做同样的事情,但在 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 次搜索。

关于python - Python 的 Google 模块的查询限制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44577928/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com