不知道现在还有多少人玩知某乎,我们那时候没事就刷刷知某乎,贴某吧,不知留下了多少足迹。
知乎上问答的质量挺高,今天咱们就对其问答内容进行爬虫实验。
可以看到,数据咱们就获取下来了,保存就可以了。
import requests import re import json import pprint # 文章不理解,我还专门个大家录制了详细的视频讲解,直接在这个扣裙里面领取 708525271 headers = { 'cookie': '__snaker__id=tx5pc8xnwNvTYvG3; SESSIONID=stAjAfHLiBBtepPE5fTov5aYQJYBLURoM8YhM5jRXqG; JOID=W1EUA0yH_mXOxwv_Jo6gdXoTh844pNVH6uoo1ASq3U7s4ybcDe3ljKTJA_YgcWoL8eX7c_wINvZ6Pe0AjXgWecM=; osd=WloVAUOG9WTMyAr0J4yvdHEShcE5r9RF5esj1Qal3EXt4SndBuzng6XCAvQvcGEK8-r6eP0KOfdxPO8PjHMXe8w=; _zap=ba7095c9-0aae-423f-9975-92c7813e6036; d_c0=ANAWztCFPxaPTkyqOI3cpp5phHc7BJUpFhs=|1675000059; YD00517437729195%3AWM_TID=q1pMuo8yFBhAAQVQURLAPRTyEuWDd2qg; arialoadData=false; YD00517437729195%3AWM_NI=jPZTAA6q1q7YI0MPivmHxhtaLmJ7TBYjTAF34UDD36WmBPrKwe5O4Lfww1472OKDIPEwCz5Ug2Hrtg%2BMm8apy4EH%2BmnIshxyXyWNH2jmJ%2FmJIFwli06F3A4RKje5REwBUXo%3D; YD00517437729195%3AWM_NIKE=9ca17ae2e6ffcda170e2e6ee8fb246a7eb8187c142bbb48bb6d84a969b9e86d46b91bb96a6cb728ceafbd5d82af0fea7c3b92aaa9096b5c44bf6afff92b6538bf083b1ec7eaf98b889f76b90b386d8d74a9bb69ca2c539f88b8ca5b23e95b38eb1f141b5bbfbb0b748a6a9b9d2b73df29185a5cc5c87a98d9bb85fa5ee8893f76de993a3d9e47cbbec8ba9aa67ae97bd89fb739ca799afcb3aaab386d0f0428b9ab98dec3cf69afda2b75a89b6abd6d14fb59e9bb9ee37e2a3; _xsrf=8cfa292c-c915-42f3-b376-a82f56613cc3; Hm_lvt_98beee57fd2ef70ccdd5ca52b9740c49=1676462242,1676547626,1676557107,1676612193; Hm_lpvt_98beee57fd2ef70ccdd5ca52b9740c49=1676612193; captcha_session_v2=2|1:0|10:1676612193|18:captcha_session_v2|88:SWI5MW91WjcybkczamhaT1FOY0lCZWczM1h1UDBvVTBQcXFYcC9JWm9qUXlybkIvbW5MQWFvd1lpeHVLUVVTWg==|68915c879a030053a7c3b5921aa2d5974f5837adb19001b606e891ae08247c14; gdxidpyhxdE=ohaj9Ig0u1f%5CcdLdC0QAEhJE6fplEfZ%2BYp07xr3XVZCJ3JmJQRfzhckh%2BJayuMOQGReJMfCem4ZE2Slz2MHMzY4r5fkAIJpTvzYcqGPHtICLgVWSM6lR5tNj1Y0O0436Gun52GbM9HW9%2F15JME0vJYKLhdSQtwykihOokRLmLbeVXJ4K%3A1676613094284; KLBRSID=2177cbf908056c6654e972f5ddc96dc2|1676612386|1676612191', 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36' } url = 'https://www.****.com/question/584206512' html_data = requests.get(url=url, headers=headers).text json_str = re.findall('<script id="js-initialData" type="text/json">(.*?)</script>', html_data)[0] json_data = json.loads(json_str) next_url = json_data['initialState']['question']['answers']['584206512']['next'] answers = json_data['initialState']['entities']['answers'] for key in list(answers.keys()): print(answers[key]['content'])
视频我都录制了对应的视频讲解,大家直接在下方领取,包括代码!
今天的分享就到这结束了,下次见!
本站文章如无特殊说明,均为本站原创,如若转载,请注明出处:Python爬虫基础丨采集知乎问答区内容 - Python技术站