请选择 进入手机版 | 继续访问电脑版

数据家园

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 111|回复: 1

[爬虫代码] 每天涨停数据爬虫

[复制链接]

75

主题

79

帖子

490

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
490
发表于 2021-3-6 02:36:51 | 显示全部楼层 |阅读模式
  1. import requests
  2. import json
  3. import pandas as pd

  4. #http://stock.jrj.com.cn/tzzs/zdforce.shtml?to=pc
  5. url = 'http://home.flashdata2.jrj.com.cn/limitStatistic/ztForce/20210305.js'

  6. headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36'}

  7. response = requests.get(url, headers=headers)
  8. json_str = response.content.decode('gbk')
  9. json_str = json_str.replace('var yzb_ztForce=', '')
  10. index = json_str.find('Data')
  11. # print(index)
  12. data = json_str[index:]

  13. data = data.replace('Data:', '')
  14. data = data.replace('}', '')
  15. data  =data[6:-1]

  16. data = json.loads(data)
  17. hi = pd.DataFrame(data)


  18. hi.columns = ['stockcode','stockname','nowPrice','priceLimit','fcb','flb','fdMoney','firstZtTime','lastZtTime','opentime','zhenfu','force']
复制代码


回复

使用道具 举报

75

主题

79

帖子

490

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
490
 楼主| 发表于 2021-3-6 02:48:51 | 显示全部楼层
  1. import requests
  2. import json
  3. import pandas as pd



  4. def ztg(day):

  5.     #http://stock.jrj.com.cn/tzzs/zdforce.shtml?to=pc
  6.     url = 'http://home.flashdata2.jrj.com.cn/limitStatistic/ztForce/'   + day +  '.js'
  7.    
  8.     headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36'}
  9.    
  10.     response = requests.get(url, headers=headers)
  11.     json_str = response.content.decode('gbk')
  12.     json_str = json_str.replace('var yzb_ztForce=', '')
  13.     index = json_str.find('Data')
  14.     # print(index)
  15.     data = json_str[index:]
  16.    
  17.     data = data.replace('Data:', '')
  18.     data = data.replace('}', '')
  19.     data  =data[6:-1]
  20.    
  21.     data = json.loads(data)
  22.     hi = pd.DataFrame(data)
  23.    
  24.    
  25.    
  26.     hi.columns = ['stockcode','stockname','nowPrice','priceLimit','fcb','flb','fdMoney','firstZtTime','lastZtTime','opentime','zhenfu','force']

  27.     hi['day']  = day
  28.    
  29.     return hi




  30. import tushare as ts
  31. import datetime

  32. pro = ts.pro_api('7322d9b3de6e6f0a650c5f3a70ca121cb35006a52a1c8c46ee7f0c63')
  33. OpenList = pro.trade_cal(start_date='20210201')


  34. DatetimeNOW = datetime.datetime.now().strftime('%Y%m%d')
  35. kai = OpenList[(OpenList.cal_date < DatetimeNOW)&(OpenList.is_open==1)]['cal_date']


  36. zt = pd.DataFrame()

  37. for i in kai:
  38.     zt = zt.append(ztg(i))
  39.     print(i)
  40.    


  41. zt.to_csv('zt.csv')


















复制代码
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|数据家园 ( 蜀ICP备13007024号 )

GMT+8, 2021-4-12 07:55 , Processed in 0.040304 second(s), 18 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表