Google 趋势爬虫代码 429 错误

Kan*_*ang 6 python google-api web-crawler google-crawlers google-trends

我是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
Run Code Online (Sandbox Code Playgroud)

DaI*_*mTo 6

HTTP/1.1 429 请求过多内容类型:text/html 重试后:3600

请求过多

请求过多

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

  1. 放慢速度,直到找出极限。
  2. 在多台服务器上运行它,让您看起来来自不同的 IP 地址。
  3. 停止尝试在 Google 上抓取他们不想共享的数据。