爬取知乎某个用户的参与的问题讨论及回答

import requests
for i in range(1,21):
    # 数据api
    url = 'https://www.zhihu.com/api/v4/members/leedaye/answers?include=data%5B*%5D.is_normal%2Cadmin_closed_comment%2Creward_info%2Cis_collapsed%2Cannotation_action%2Cannotation_detail%2Ccollapse_reason%2Ccollapsed_by%2Csuggest_edit%2Ccomment_count%2Ccan_comment%2Ccontent%2Cvoteup_count%2Creshipment_settings%2Ccomment_permission%2Cmark_infos%2Ccreated_time%2Cupdated_time%2Creview_info%2Cquestion%2Cexcerpt%2Crelationship.is_authorized%2Cvoting%2Cis_author%2Cis_thanked%2Cis_nothelp%3Bdata%5B*%5D.author.badge%5B%3F(type%3Dbest_answerer)%5D.topics&offset={}&limit=20&sort_by=created'.format((i-1)*20)
    headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36',
    }

    response = requests.get(url,headers=headers)

    date = response.json()
    for res in date['data']:
        print('问题:'+ res['question']['title'])
        print('回答:'+ res['excerpt'])

    print('第%d页结束'%i)
展开阅读全文

没有更多推荐了,返回首页