我能够通过为每次迭代重新建立连接来捕捉错误,虽然效率低下,但完成了任务:
r = pd.DataFrame()
s = pd.DataFrame()
for i in listofwords:
try:
pytrend = TrendReq(google_username, google_password, custom_useragent='Pytrends')
pytrend.build_payload(kw_list=[i])
Related_df = pytrend.related_queries()
s = s.append(Related_df[i]['top'].head(3))
r = r.append(Related_df[i]['rising']['query'].head(3))
except:
pass
我能够通过为每次迭代重新建立连接来捕捉错误,虽然效率低下,但完成了任务:
r = pd.DataFrame() s = pd.DataFrame() for i in listofwords: try: pytrend = TrendReq(google_username, google_password, custom_useragent='Pytrends') pytrend.build_payload(kw_list=[i]) Related_df = pytrend.related_queries() s = s.append(Related_df[i]['top'].head(3)) r = r.append(Related_df[i]['rising']['query'].head(3)) except: pass
相关问题 更多 >
编程相关推荐