一、Requests库安装
可以使用命令提示符指令直接安装requests库使用
pip install requests
二、爬取JSON数据
(1)、点击网络
(2)、刷新网页
(3)、这里有一些数据类型,选择全部
(4)、必须了解信息
三、了解信息之后开始实践
import requests
import json# 网页的url
url1 = 'https://piaofang.maoyan.com/dashboard-ajax?orderType=0&uuid=1938b6042b7c8-095c6f731f042e-26011851-1fa400-1938b6042b7c8&timeStamp=1733215970935&User-Agent=TW96aWxsYS81LjAgKFdpbmRvd3MgTlQgMTAuMDsgV2luNjQ7IHg2NCkgQXBwbGVXZWJLaXQvNTM3LjM2IChLSFRNTCwgbGlrZSBHZWNrbykgQ2hyb21lLzEzMS4wLjAuMCBTYWZhcmkvNTM3LjM2&index=713&channelId=40009&sVersion=2&signKey=b9ba8a808c9acc49342231412025a24b'# 一些UA伪装信息
headers = {'cookie': '_lxsdk_cuid=1938b6042b7c8-095c6f731f042e-26011851-1fa400-1938b6042b7c8; _lxsdk=1938b6042b7c8-095c6f731f042e-26011851-1fa400-1938b6042b7c8; _lx_utm=utm_source%3DBaidu%26utm_medium%3Dorganic; _lxsdk_s=1938bb8371a-307-90-43f%7C%7C2','host': 'piaofang.maoyan.com','referer': 'https://piaofang.maoyan.com/dashboard','user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36'
}
# 发送请求
response = requests.get(url=url1, headers=headers)
# 设定编码
response.encoding = 'utf-8'
info = response.text
print(info)
# 将上述爬取到的json格式的字符串转成python中的字典进行数据分析
info = json.loads(info)
获取后的信息要经过处理才能清晰的展现。