在python上使用pytrends库时出现“属性错误”

2024-10-01 07:30:36 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用pytrends库运行一个脚本来获取Google趋势

import pytrends
kw_list = ["covid"]
pytrends.build_payload(kw_list, cat=0, timeframe='2021-02-01 2021-07-09', geo='BR', gprop='')
gt_o3_ytd1 = pytrends.interest_over_time()

我收到以下错误消息:

AttributeError                            Traceback (most recent call last)
<ipython-input-4-e6a3a9855c66> in <module>
      2 
      3 kw_list = ["covid"]
----> 4 pytrends.build_payload(kw_list, cat=0, timeframe='2021-02-01 2021-07-09', geo='BR', gprop='')
      5 gt_o3_ytd1 = pytrends.interest_over_time()

AttributeError: module 'pytrends' has no attribute 'build_payload'

Tags: brgtbuildlistcatgeopayloadkw
2条回答
# import the TrendReq method from the pytrends request module
from pytrends.request import TrendReq

# execute the TrendReq method by passing the host language (hl) and timezone (tz) parameters
pytrends = TrendReq(hl='en-US', tz=360)

kw_list = ["covid"]
pytrends.build_payload(kw_list, cat=0, timeframe='2021-02-01 2021-07-09', geo='BR', gprop='')
gt_o3_ytd1 = pytrends.interest_over_time()
gt_o3_ytd1

试一试

mytrend = pytrends.TrendReq()
mytrend.build_payload(kw_list, cat=0, timeframe='2021-02-01 2021-07-09', geo='BR', gprop='')
gt_o3_ytd1 = pytrends.interest_over_time()

相关问题 更多 >