原文 https://mp.weixin.qq.com/s/PyuIZelzT01E3rFDPcReXg
背景
爬虫练习仅为学习,不做商用,如有侵权,烦请联系删除!
目标网址
https://data.eastmoney.com/hsgt/hsgtDetail/scgk.html
爬取目标
依据股票代码爬取股票历史数据
相关库名
requests json
实现逻辑
目标网页-查询指定股票-分析network-找到接口-分析返回数据-读取数据
代码实现
网址
# 目标网址
url = "https://push2his.eastmoney.com/api/qt/stock/kline/get?"
参数
# 请求参数
params = {
"fields1": "f1,f2,f3,f4,f5,f6",
"fields2": "f51,f52,f53,f54,f55,f56,f57,f58,f59,f60,f61",
"fqt": "0",
"end": "20500101",
"ut": "fa5fd1943c7b386f172d6893dbfba10b",
"cb": "jQuery351018337495712960572_1710131594655",
"klt": "101",
"secid": code,
"fqt": "1",
"lmt": "10",
"_": "1710131594667"
}
请求头
# 模拟浏览器请求的headers
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3',
'Host': 'push2his.eastmoney.com',
'Referer': 'https://quote.eastmoney.com/sz000610.html'
}
执行结果
获取源码请阅读原文