|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 kunkun_1230 于 2017-9-30 09:51 编辑
最近,看完小甲鱼的python教学视频后,准备爬取一下知乎上自己的关注者,并计划拿到数据之后,做一个画像,看一下关注我的都是什么样的人。
根据网上已经有的代码,外加自己编辑的代码,现在可以成功登陆知乎,并且可以顺利的返回xsrf数据了。
但是获得个人主页的时候,还是返回了403,信息错误的问题,一直没有得到个人主页的详细信息(获取个人主页的代码如下)。
- #------------------------------------这是获取数据的代码-----------------------
- def getdetail():
- follower_url='https://www.zhihu.com/people/kunkun_1230/followers'
- follower_headers={'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:55.0) Gecko/20100101 Firefox/55.0',
- 'Referer': 'https://www.zhihu.com/people/kunkun_1230/followers',
- 'Origin': 'https://www.zhihu.com',
- 'Accept-Encoding': 'gzip, deflate, br',
- 'Accept': '*/*'}
- m_data={'_xsrf':str(get_xsrf())}
- result = session.post(follower_url, data=m_data, headers=follower_headers)
- soup=bs(result.content,'lxml')
- with open('soup','w',encoding='utf-8') as f:
- f.write(str(soup))
复制代码
全部的代码见链接zhihu_login_get follower.py
(https://github.com/kunkun1230/Python-/tree/master/%E7%99%BB%E5%BD%95%E7%9F%A5%E4%B9%8E)
这个问题困扰我好久了,请各位大神帮忙看一下,问题出在什么地方,并帮忙改正一下。万分感谢!!!! |
|