如何避免使用此代码获得 HTTP 错误 429: Too Many Requests 或使用此代码处理它?我试过添加 sleep.time(sec) 但它不起作用
import googlesearch
import pandas as pd
with open('Unknown.xlsx', "rb") as f:
df = pd.read_excel(f) # can also index sheet by name or fetch all sheets
mylist = df['Short Code'].tolist()
try:
from googlesearch import search
except ImportError:
print("No module named 'google' found")
# to search
shortcode = int()
shortcode_list = mylist
for i in range(len(shortcode_list)):
shortcode = shortcode_list[i]
string = "text * to " + '"' + str(shortcode) + '"'
print(string)
query = string
# time.sleep(1)
for j in search(query, tld="co.in", num=10, stop=10, pause=2, country='US',
user_agent=googlesearch.get_random_user_agent(), verify_ssl=True):
print(j)