我是python新手并使用unofficial pytrends
API抓取Google Trend。我有2000多个关键字作为DNA列表并尝试抓取数据。当我运行此代码时,它显示为" Google返回了代码为429"即使我添加了time.sleep(1)
。任何人都可以帮我解决这个问题吗?
下面是我的代码
#DNA has 2000+ lists
from pytrends.request import TrendReq
import pandas as pd
import xlsxwriter
import time
pytrends = TrendReq(hl='en-US,tz=360')
Data = pd.DataFrame()
#Google Trend Crawler
for i in range(DNA[i]):
time.sleep(1)
kw_list = [DNA[i]]
pytrends.build_payload(kw_list, cat=0, timeframe='today 5-y', geo='', gprop='')
df = pd.DataFrame(pytrends.interest_over_time())
#Setting a Google Trend Dates
if(i==0):
Googledate = pd.DataFrame(pytrends.interest_over_time())
Data['Date'] = Googledate.index
Data.set_index('Date', inplace=True)
#results
if(df.empty == True):
Data[DNA[i]] = ""
else:
df.index.name = 'Date'
df.reset_index(inplace=True)
Data[DNA[i]] = df.loc[:, DNA[i]]
Data
答案 0 :(得分:3)
HTTP / 1.1 429请求太多Content-Type:text / html Retry-After: 3600
请求太多
请求过多
Google趋势没有官方API。谷歌可能对来自同一IP的请求数量设置了限制。