使用pytrends抓取冠状病毒数据

时间:2020-03-21 21:30:55

标签: python web-scraping

kw = ['Coronavirus']

import pandas as pd
from pytrends.request import TrendReq
pytrends = TrendReq(hl='en us',tz=360)

kw = ['Coronavirus']
search_df = pytrends.get_historical_interest(kw)
search_df

以上是我的代码。我不确定如何解释我的输出吗?我也希望输出的数据会更加丰富,例如指出该关键字的趋势。

感谢您的帮助!

1 个答案:

答案 0 :(得分:1)

您的语法全都错了。试试:

from pytrends.request import TrendReq

pytrend = TrendReq(hl='en-US', tz=360, retries=10, backoff_factor=0.5)

search_df = pytrend.get_historical_interest(
    keywords=['Coronavirus'],
    year_start=2020,
    year_end=2020,
    month_end=4,
    month_start=2

)
print(search_df)

pytrend.build_payload(kw_list=['Coronavirus'])

# Interest Over Time
interest_over_time_df = pytrend.interest_over_time()
print(interest_over_time_df.tail())

# Interest by Region
interest_by_region_df = pytrend.interest_by_region()
print(interest_by_region_df.head())

主要来自https://github.com/GeneralMills/pytrends/blob/master/examples/example.py