longxiaofei / spider-BaiduIndex

data sdk for baidu Index
MIT License
749 stars 229 forks source link

TypeError: string indices must be integers #12

Closed aakhmetz closed 4 years ago

aakhmetz commented 4 years ago

Probably, because of some change in Python, I tried to run the demo code and get the following error :(

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-25-d685484c0ecf> in <module>
     12     keywords = ['爬虫', 'lol', '张艺兴', '人工智能', '华为', '武林外传']
     13     baidu_index = BaiduIndex(keywords, '2018-01-01', '2019-05-02')
---> 14     for index in baidu_index.get_index():
     15         print(index)

~/scripts/get_index.py in get_index(self)
     56                     start_date=params_data['start_date'],
     57                     end_date=params_data['end_date'],
---> 58                     keywords=params_data['keywords']
     59                 )
     60                 key = self._get_key(uniqid)

~/scripts/get_index.py in _get_encrypt_datas(self, start_date, end_date, keywords)
    107         html = self._http_get(url)
    108         datas = json.loads(html)
--> 109         uniqid = datas['data']['uniqid']
    110         encrypt_datas = []
    111         for single_data in datas['data']['userIndexes']:

TypeError: string indices must be integers
aakhmetz commented 4 years ago

I understood. It works - thank you!

longxiaofei commented 4 years ago

I understood. It works - thank you!

I just wanted to reply to you, you may need a cookie.