我在爬取一个网站(https://www.zhihu.com/people/xie-ke-41/followers),我想获取所有关注者的信息。正如你所看到的,一些追随者在Chrome的信息与AJAX带来的,我用的开发者工具,并找到URL the url which has followers' information无法从beautiful_soup对象提取数据
我的代码:
import requests
from bs4 import BeautifulSoup
zhihu_rl = 'https://www.zhihu.com/node/ProfileFollowersListV2'
data = {
'method': 'next',
'params': '{"offset":20,"order_by":"created","hash_id":"86858a7a4aa77d290364625efcaacb70"}'}
headers = {
'Host': 'www.zhihu.com',
'Origin': 'https://www.zhihu.com',
'Referer': 'https://www.zhihu.com/people/xie-ke-41/followers',
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.116 Safari/537.36',
'X-Requested-With': 'XMLHttpRequest',
'X-Xsrftoken': 'foo',
'Cookie':'xxxxxxxxxxxx'}
rep = requests.post(url=zhihu_rl, data=data, headers=headers)
bsobj = BeautifulSoup(rep.text, 'html.parser')
print(bsobj.find_all('div', {'class': "zm-profile-card zm-profile-section-item zg-clear no-hovercard"}))
和一个空的列表返回。 我可以看到的信息是开发人员的工具: ,为什么不能bs4提取它们? PS:我可以得到所有的div,但是当我限制属性。它失败了
我无法访问该网站。从我看到的最后一行开始,项目之前不应该有空格? 'zm-profile-section-item' –
对不起,这是我的拼写错误 – dogewang