python爬取知乎评论

点击评论,出现异步加载的请求

import json

import  requests
from lxml import etree
from time import sleep


url = "https://www.zhihu.com/api/v4/answers/974431591/root_comments?order=normal&limit=20&offset=0&status=open"
headers = {
    "User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36",
    "Refer":"https://www.zhihu.com/"
}
resp = requests.get(url,headers=headers)
content = resp.content.decode('utf-8')
res = json.loads(content)
print(res['data'])
data = res['data']

for item in data:
    print(item['content'])
    print("*"*30)
原文地址:https://www.cnblogs.com/brady-wang/p/12491163.html