上海证券交易所日数据概况爬虫

# from urllib import request
# # resp=request.urlopen("http://www.hkexnews.hk/sdw/search/mutualmarket_c.aspx?t=sh")
# # print(resp.read(10))
import requests
from lxml import etree
import json
import time
import datetime
headers={"Referer": "http://www.sse.com.cn/market/stockdata/overview/day/","Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
"Accept-Encoding": "gzip, deflate",
"Accept-Language": "zh-CN,zh;q=0.9",
"Cache-Control": "max-age=0",
"Connection": "keep-alive",
"Cookie": "sseMenuSpecial=8465; yfx_c_g_u_id_10000042=_ck18102916221510722963893155845; yfx_f_l_v_t_10000042=f_t_1540801335062__r_t_1540801335062__v_t_1540801335062__r_c_0; VISITED_MENU=%5B%228466%22%5D",
"Host": "www.sse.com.cn",
"Upgrade-Insecure-Requests": "1",
"User-Agent": "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3551.3 Mobile Safari/537.36"
}
params={"jsonCallBack": "jsonpCallback18631",
"searchDate": "2018-10-24",
"prodType": "gp",
"_":"1540803198930"}
def down_trade(startime,etime):
stime = datetime.datetime.strptime(startime, "%Y-%m-%d")
etime = datetime.datetime.strptime(etime, "%Y-%m-%d")
while stime<=etime:
stime+=datetime.timedelta(days=1)
riqi=stime.strftime("%Y-%m-%d")
print("开始处理日期:"+riqi)
shanhaicodeavg(riqi)

def shanhaicodeavg(day):
url="http://query.sse.com.cn/marketdata/tradedata/queryTradingByProdTypeData.do?jsonCallBack=jsonpCallback44691&searchDate="+day+"&prodType=gp&_=1540803198932"
response=requests.get(url,headers=headers)
response.encoding="utf-8"
text=response.text
#print(text)
jsontext1=text.strip('jsonpCallback44691')#最终结果json格式
jsontext=jsontext1.strip('(').strip(')')
fh = open(day+".txt", 'w', encoding='utf-8')
fh.write(jsontext)
fh.close()
if __name__ == "__main__":
down_trade("2000-01-01","2018-10-29")
print('ok')

转载于:https://www.cnblogs.com/guoshanyun/p/9883190.html

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值