如何使用python从脚本启动爬取CSDN热搜榜存到数据库?想要现在可以运行的代码 或者指导
这个是数据接口,requests.get这个网址就行了,有帮助麻烦点个采纳【本回答右上角】,谢谢~~
https://blog.csdn.net/phoenix/web/blog/hot-rank?page=0&pageSize=25 https://blog.csdn.net/phoenix/web/blog/hot-rank?page=0&pageSize=25
page为要采集的页码,替换下就能继续采集其他的内容
import requests
url="https://blog.csdn.net/phoenix/web/blog/hot-rank?page={}&pageSize=25"
headers={"Referer":"https://www.csdn.net/?spm=1005.2026.3001.4476",
"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36"}
for page in range(3):#采集前3页数据
requrl=url.format(page)
data=requests.get(requrl,headers=headers).json()
if data['code']==200:
for item in data['data']:
print('标题:%s 热度:%s'%(item['articleTitle'],item['pcHotRankScore']))
数据结构
参考一下: https://www.icode9.com/content-4-941200.html https://www.icode9.com/content-4-941200.html