2

朋友股票亏惨了,我一怒用Python爬取了证券最新数据

 2 years ago
source link: https://blog.csdn.net/AI19970205/article/details/120953778
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

大家好,我是辣条。

 抓取目标:

url:http://webapi.cninfo.com.cn/#/marketDataDate
数据目标: 获取 证券代码 证券简称 交易日期  开盘价 最高价 最低价 收盘价 成交数量
难点: 请求头参数mcode 加密生成 

使用第三方库:

1. requests
2. execjs
3. js2py
4. math
5. time
6. pandas
1. 谷歌浏览器
2. pycharm
3. python3.7

页面分析:

进入页面,鼠标右击,选择检查 -> 弹出浏览器开发者工具 -> Netword -> 选择xhr -> 刷新页面

 找到接口,观察接口数据情况:

此接口为post请求,需要提交两个表单参数。

代码片段:

请求成功, 但是有时效性的问题,等过了几分钟后,就无权限访问了,仔细观察发现特殊参数mcode。

开始JS找加密参数生成位置: (注意需要重新刷新页面,不然会出现没有js情况)

 问题来了,好几个js文件,怎么确定那个是我们需要的?

使用第二种搜索方式,根据url的请求地址搜索:

打上断点后 直接刷新页面 开始调试

继续调试,看看这个missjson是干啥的。

 下面把这些js扣下来执行

 👇🏻 疑难解答、学习资料、路线导图可通过搜索下方 👇🏻


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK