I am new to python and using unofficial pytrends
API to crawl Google Trend. I have 2000+ keywords as DNA list and try to crawl data. When I run this code, it appears with "Google returned a response with code 429" even though I added time.sleep(1)
. Can anyone help me with this problem?
below is my code
#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