crawl-zsxq
crawl-zsxq copied to clipboard
报错TypeError: 'NoneType' object is not iterable
File "D:/SourceCodes/crawl-zsxq-master/crawl1.py", line 37, in get_data for topic in json.loads(f.read()).get('resp_data').get('topics'):
TypeError: 'NoneType' object is not iterable
由于请求头中的结构变更,所以获取不到api数据,将28行代码
'Authorization': 'DD282FEB-EDD7-A50E-6C94-344947B6E723',
更改为:
'Cookie':'zsxq_access_token=DD282FEB-EDD7-A50E-6C94-344947B6E723',
当然,你需要换成自己的Cookie,在此我只是提供一个示例。
目前cookie变多了,添加了还是不行
当前如何解决? @cirno99
很容易解决的,header改成这样的形式
headers = {
'Cookie':'UM_distinctid=165ecede306116a-083654f0777282-34607908-13c680-165ecede3075fd',
'Cookie':'sensorsdata2015jssdkcross=%7B%22distinct_id%22%3A%2216846276920ae3-0e9d710efddd66-10336654-1296000-16846276921bf%22%2C%22%24device_id%22%3A%2216846276920ae3-0e9d710efddd66-10336654-1296000-16846276921bf%22%2C%22props%22%3A%7B%22%24latest_traffic_source_type%22%3A%22%E7%9B%B4%E6%8E%A5%E6%B5%81%E9%87%8F%22%2C%22%24latest_referrer%22%3A%22%22%2C%22%24latest_referrer_host%22%3A%22%22%2C%22%24latest_search_keyword%22%3A%22%E6%9C%AA%E5%8F%96%E5%88%B0%E5%80%BC_%E7%9B%B4%E6%8E%A5%E6%89%93%E5%BC%80%22%7D%7D',
'Cookie':'zsxq_access_token=9540C63F-C4D5-5461-C3ED-9376940BFCAA',
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36'
}
我也遇到了这样的问题,我的文件头已经加了,Cookie,现在是一行的: headers = { 'Cookie': 'zsxq_access_token=A690791D-01A1-5F69-6E60-2409399C89A5', 'Host': 'api.zsxq.com', 'Origin': 'https: // wx.zsxq.com', 'Referer': 'https: // wx.zsxq.com / dweb /', 'X-Request-Id': 'e94e2a33-397f-7573-5daf-bf5c0ca0e52d', 'X-Signature': '5b116076cb59fdf1607416c746dd7803e9cee4cf', 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36' } 但是还是遇到了这样的错误提示: File "/Users/mac/work/getweb/crawl-zsxq/crawl.py", line 42, in get_data for topic in json.loads(f.read()).get('resp_data').get('topics'): TypeError: 'NoneType' object is not iterable
请问是怎么回事,怎么解决这个问题?
我也遇到了这样的问题,我的文件头已经加了,Cookie,现在是一行的: headers = { 'Cookie': 'zsxq_access_token=A690791D-01A1-5F69-6E60-2409399C89A5', 'Host': 'api.zsxq.com', 'Origin': 'https: // wx.zsxq.com', 'Referer': 'https: // wx.zsxq.com / dweb /', 'X-Request-Id': 'e94e2a33-397f-7573-5daf-bf5c0ca0e52d', 'X-Signature': '5b116076cb59fdf1607416c746dd7803e9cee4cf', 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36' } 但是还是遇到了这样的错误提示: File "/Users/mac/work/getweb/crawl-zsxq/crawl.py", line 42, in get_data for topic in json.loads(f.read()).get('resp_data').get('topics'): TypeError: 'NoneType' object is not iterable
请问是怎么回事,怎么解决这个问题?
可以用 xingstarx的方法解决
TypeError: 'NoneType' object is not iterable
请问大家是怎么解决这个问题的呢?