关于用python抓取知乎关注的人?

听上去有点像前两天爬取回答的点赞用户列表时遇到的json数据……
你可以先看一下这里如何入门 Python 爬虫? - 段晓晨的回答
不过那个不用POST
是这样的。_xsrf=f6cf0e800c0d33fdf8c8c4f3d0701f4amethod=nextparams={"offset":20,"order_by":"created","hash_id":"fc91ae5ff90c3248f0fd00102d6c0f08"}_xsrf 是你登陆时服务器给的,你可以试着用http://urllib2.urlopen.page.info()方法看能不能把登陆成功以后的_xsrf获取出来
params 里面,offset是每次的偏移值,20,40,60,这样每次20递增。order_by不用管。
hash_id对于每个用户来讲是唯一的,我换了两个账号来查看同一个用户的关注者,发现hash_id不会变。
这样你就得到了完整的post数据。
需要注意的一点是,post数据时应该发送 k:v, k1:v2... 而这里的value值不能是一个dict,比如这里的params就是一个dict。所以在发送时应该将整体数据先使用urllib.urlencode()方法。
大概是这样。
关于用python抓取知乎关注的人?

这样就是你在抓包时看到的所谓源代码
关于用python抓取知乎关注的人?

自己先做了这么多…你可以再自己探索一下,大概方向应该就是这样的。

■网友
用chrome的开发者工具,Firefox的firebug,或者第三方的fiddler,抓包仔细分析具体的请求过程就好。尤其是fiddler,前端神器,写爬虫必备。
■网友
swoec/spider
這是我之前寫的抓取用戶好友的爬蟲,
先獲取好友數,然後一頁一頁抓取,取得好友的名稱和籤名檔。
【关于用python抓取关注的人?】

■网友
不知道题主现在问题解决没,放上之前看到的一个爬虫,觉得写的很好,是 @egrcc写的,我把地址放在这,相信题主这么聪明,能找到你需要的部分。egrcc/zhihu-python · GitHub另,如果 @egrcc 觉得我放在这不太妥当,请评论,我会及时删除,谢谢您,我的第一个爬虫就是照着您的程序写的。
■网友
你好,已经改版,以"梁边妖"主页为例,可以爬取https://www.zhihu.com/people/liangbianyao/followers?page=1,设置遍历page=i获取followers,其中单页面简单爬虫代码可以这样:# -*- coding: utf-8 -*-"""Spyder EditorThis is a temporary script file."""import urllibimport urllib.requestfrom bs4 import BeautifulSoupclass spider_zhihu(): def __init__(self): self.followers_page = \u0026#39;https://www.zhihu.com/people/liangbianyao/followers?page=1\u0026#39; self.user_agent = \u0026#39;Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36 OPR/42.0.2393.94\u0026#39; self.head = {\u0026#39;User-Agent\u0026#39;:self.user_agent} def getopener(self, head): opener = urllib.request.build_opener() header = for key, value in head.items(): elem = (key, value) header.append(elem) opener.addheaders = header return opener def request_page(self, page): opener = self.getopener(self.head) url = opener.open(page).read().decode(\u0026#39;utf-8\u0026#39;) page = BeautifulSoup(url) followers = page.find_all(attrs=\u0026#39;UserLink-link\u0026#39;) followers_list = for i in range(1, len(followers), 2):#遍历获取用户信息 followers_list.append(.attrs, followers.string]) return followers_list if __name__ == \u0026#39;__main__\u0026#39;: t = spider_zhihu() followers_list = t.request_page(t.followers_page)


推荐阅读