3

我是 python 新手,使用非官方pytrendsAPI来抓取 Google Trend。我有 2000 多个关键字作为 DNA 列表并尝试抓取数据。当我运行此代码时,即使我添加了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
4

1 回答 1

5

HTTP/1.1 429 请求太多内容类型:文本/html 重试后:3600

请求过多

请求过多

谷歌趋势没有官方 API。谷歌可能已经对来自同一 IP 的请求数量进行了限制。

  1. 放慢速度,直到你弄清楚极限。
  2. 在多台服务器上运行它,让您看起来像是来自不同的 IP 地址。
  3. 停止尝试在 Google 上抓取他们不想分享的数据。
于 2017-11-27T10:19:24.867 回答