python爬虫 爬取知乎用户的用户信息

博主利用Python爬虫技术,通过知乎用户分享的文章找到其ID,尽管用户已更改名字,但无法改变ID。通过尝试不同ID组合,最终成功找到心仪女生的知乎主页,从而更深入地了解她的兴趣和关注点。
摘要由CSDN通过智能技术生成

我用python爬虫找到了不想告诉我她知乎ID的妹纸的ID…….

在我做了这件事情之后 , 她觉得我越来越懂她了 , 嘻嘻

有一天 , 我发现我心仪已久的妹纸在朋友圈里分享了知乎专栏的文章 , 就知道她也刷知乎 . 如果在知乎上关注她 , 我就能知道 , 她最近关注什么 , 心里想些什么 , 了解了解她喜欢的方面 , 还能作为谈资 , 简直太赞了 (*^^)v .
但是输入她的名字…… 在知乎上根本找不到好吗 (๑`灬´๑)
我们两个聊天的时候 , 刚好说到了她分享的那篇文章 ,
我很自然的说: “知乎上你用的不是真名呀, 就我这么天真用了真名..”
她笑着说:”那个可以改呀” ,
“凭什么知乎团队不让我改啊!!! “,我答道,” 不如我们互粉吧^_- ”
哎 , 于是她打开zhihu , 看了看我的主页 , 并没有关注我…… 可能是赞太少了吧… 达不到她的要求 , 或者她不想让我知道她在看什么吧 , 也许她希望自己的知乎是交浅言深 , 不希望被身边人看见… (๑-﹏-๑) 失望.

我回去想了想 , 她说名字可以改 , 那她可能以前也用的是真名 , 找到破绽了!
知乎的名字可以改 , 但是id是改不了的 !
每个人的主页地址 , people后面那个就是TA的id,
http://www.zhihu.com/people/zhang-san-12-45
例如张三同名很多 , 后面就会加上数字. 她的名字拼音相同的较多 , 我试了一下 , 这个数字是不超过100的. 它的组合方式有 zhang-san , zhang-san-1 zhang-san-12-43 依次类推.

好 , 现在我就可以开始寻找她的账号了! 既然她改名了 , 那她名字满足的条件一定是: 昵称的拼音不是真名. 这个用pypinyin模块可以解决 , 这样子 , 需要我人工查看的主页就少很多了.

  1. 在github上 下
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
可以使用 Python 的 Requests 和 BeautifulSoup 库来爬取知乎用户信息。首先需要登录知乎获取 cookie,然后通过模拟登录获取到用户的个人主页,再使用 BeautifulSoup 解析页面获取用户信息。 以下是示例代码: ```python import requests from bs4 import BeautifulSoup # 登录知乎并获取 cookie session = requests.Session() headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'} login_url = 'https://www.zhihu.com/signin' response = session.get(login_url, headers=headers) soup = BeautifulSoup(response.text, 'html.parser') _xsrf = soup.find('input', attrs={'name': '_xsrf'})['value'] captcha_url = soup.find('img', attrs={'class': 'Captcha-englishImg'})['src'] # 模拟登录获取用户信息 login_data = { '_xsrf': _xsrf, 'email': 'your_account', 'password': 'your_password', 'captcha': input('请输入验证码' + captcha_url), 'remember_me': 'true' } session.post(login_url, headers=headers, data=login_data) user_url = 'https://www.zhihu.com/people/username' response = session.get(user_url, headers=headers) soup = BeautifulSoup(response.text, 'html.parser') # 解析页面获取用户信息 name = soup.find('span', attrs={'class': 'ProfileHeader-name'}).text headline = soup.find('span', attrs={'class': 'RichText ztext ProfileHeader-headline'}).text description = soup.find('div', attrs={'class': 'ProfileHeader-infoItem ProfileHeader-description'}).find('span', attrs={'class': 'RichText ztext'}).text.strip() location = soup.find('div', attrs={'class': 'ProfileHeader-infoItem ProfileHeader-location'}).find('span', attrs={'class': 'ProfileHeader-detailValue'}).text.strip() business = soup.find('div', attrs={'class': 'ProfileHeader-infoItem ProfileHeader-business'}).find('span', attrs={'class': 'ProfileHeader-detailValue'}).text.strip() employment = soup.find('div', attrs={'class': 'ProfileHeader-infoItem ProfileHeader-employment'}).find('span', attrs={'class': 'ProfileHeader-detailValue'}).text.strip() position = soup.find('div', attrs={'class': 'ProfileHeader-infoItem ProfileHeader-position'}).find('span', attrs={'class': 'ProfileHeader-detailValue'}).text.strip() education = soup.find('div', attrs={'class': 'ProfileHeader-infoItem ProfileHeader-education'}).find('span', attrs={'class': 'ProfileHeader-detailValue'}).text.strip() major = soup.find('div', attrs={'class': 'ProfileHeader-infoItem ProfileHeader-major'}).find('span', attrs={'class': 'ProfileHeader-detailValue'}).text.strip() ``` 以上代码中,需要替换 `your_account` 和 `your_password` 为你的知乎登录账号和密码,并将 `username` 替换为你要爬取用户用户名。另外,为了防止被知乎爬虫机制检测到,最好加上一些随机的等待时间和 User-Agent 等信息
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值