爬取知乎信息报错--TypeError: string indices must be integers

import requests
import json
import pymysql

num=0 #设定爬取次数
user_all=[] #存放本次运行的用户

def get_url(url): #获取链接内容
header_info = {
"User-Agent": 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36',
}
user_url =url
response =requests.get(user_url, headers=header_info)
data = response.content
data = data.decode('utf-8') #设置字符集
return data

def get_follower(userID): #解析内容,获取关注用户
list=[]
url = 'https://www.zhihu.com/api/v4/members/'+userID+'/followees?' \
'include=data%5B*%5D.answer_count%2Carticles_count%2Cgender%2Cfollower_count%' \
'2Cis_followed%2Cis_following%2Cbadge%5B%3F(type%3Dbest_answerer)%5D.topics&offset=0&limit=20'
data = get_url(url)
data = json.loads(data)
print(data)
for user in data:
list.append(user['url_token'])
return list

get_follower('kaiqu')

报错信息
TypeError                                 Traceback (most recent call last)
<ipython-input-22-0194a6f553cc> in <module>
     32 
     33 
---> 34 get_follower('kaiqu')
     35 
     36 

<ipython-input-22-0194a6f553cc> in get_follower(userID)
     28     print(data)
     29     for user in data:
---> 30         list.append(user['url_token'])
     31     return list
     32 

TypeError: string indices must be integers

1个回答

可能是 30 行的访问方法错误了。
https://blog.csdn.net/weixin_43256057/article/details/83867876

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!