我运行以下代码以获取错误:
from pytrends.request import TrendReq
google_username = ''
google_password = ''
pytrend = TrendReq(google_username, google_password, custom_useragent='My Pytrends Script')
pytrend.build_payload(kw_list=['apple', 'sony'], timeframe = 'now 7-d')
pytrend.trending_searches()
JSONDecodeError:期望值:第1行第1列(字符0)
pytrend.top_charts(date='201611', cid='apple', geo='US', cat='')
JSONDecodeError:期望值:第1行第1列(字符0)
有类似问题的人吗? 非常感谢!
答案 0 :(得分:0)
看起来pip中的pytrends已经过时了。尝试从git
获取pytrendspip install git+https://github.com/GeneralMills/pytrends@master --upgrade
更新1:
至少他们使用different URL for trending searches。 源自pip(pytrends / request.py):
def trending_searches(self):
"""Request data from Google's Trending Searches section and return a dataframe"""
# make the request
req_url = "https://www.google.com/trends/hottrends/hotItems"
来自主分公司的来源:
TRENDING_SEARCHES_URL = 'https://trends.google.com/trends/hottrends/hotItems'
# some code
def trending_searches(self):
"""Request data from Google's Trending Searches section and return a dataframe"""
# make the request
forms = {'ajax': 1, 'pn': 'p1', 'htd': '', 'htv': 'l'}
req_json = self._get_data(
url=TrendReq.TRENDING_SEARCHES_URL,
method=TrendReq.POST_METHOD,
data=forms,
)['trendsByDateList']
result_df = pd.DataFrame()