2017-05-15 113 views
0

我運行下面的代碼來獲得一個錯誤:pytrends_json.decoder.JSONDecodeError:期待值:第1行第1列(CHAR 0)

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列(CHAR 0)

pytrend.top_charts(date='201611', cid='apple', geo='US', cat='') 

JSONDecodeError:期待值:第1行第1列(CHAR 0)具有類似的問題

任何? 非常感謝!

回答

0

在pip中看起來像pytrends是過時的。嘗試從混帳

pip install git+https://github.com/GeneralMills/[email protected] --upgrade 

更新1採取pytrends:

至少他們使用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() 
+0

畫中畫版本是9.0.1和pytrends版本是4.1.1 他們兩人都是最新版本... –

+0

@VickyChang我剛剛更新了我的答案 –

+0

感謝您的幫助! –

相關問題