-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstock information acquirement
More file actions
47 lines (31 loc) · 1.68 KB
/
stock information acquirement
File metadata and controls
47 lines (31 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
"""
想研究下python如何与股票研究结合到一起,不过本篇最后仅限于将股票数据下载到本地
网易财经获取股票历史数据的接口
http://quotes.money.163.com/service/chddata.html?code=[code]&start=[yyyyMMdd]&end=[yyyyMMdd]&fields=TCLOSE;HIGH;LOW;TOPEN;LCLOSE;CHG;PCHG;TURNOVER;VOTURNOVER;VATURNOVER;TCAP;MCAP
教程来源:https://www.sohu.com/a/353015160_99987664
"""
import urllib.request
import re #正则表达式
import glob #查找文件路径
import time
allCodelist=[
'601099','601258','600010','600050','601668','601288','600604','600157','601519','600030',#上海A股
'900902','900941','900948','900938','900947','900932','900907','900906','900903','900919',#上海B股
'000725','300059','002131','300116','002195','002526','002477','000536','300104','000793',#深圳A股
'200725','200160','200018','200037','200488','200168','200468','200058','200012','200625' #深圳B股
]
for code in allCodelist:
if (code[0] == '6'):#沪A股
#print('正在获取%s股票数据...' % code)
url = 'http://quotes.money.163.com/service/chddata.html?code=0' + code + '&start=20190101&end=20200808&fields=TCLOSE;HIGH;LOW;TOPEN;LCLOSE;CHG;PCHG;TURNOVER;VOTURNOVER;VATURNOVER;TCAP;MCAP'
#print(url)
urllib.request.urlretrieve(url, 'd:\\股票\\' + code + '.csv')#需要提前新建好D盘的“股票”目录,将数据写入csv文件
csvx_list = glob.glob('d:\\股票\\*.csv')
print('总共发现%s个CSV文件' % len(csvx_list))
time.sleep(2)
print('正在处理............')
for i in csvx_list:
fr = open(i, 'r').read()
with open('csv_to_csv.csv', 'a') as f:#合并csv文件
f.write(fr)
print('写入完毕!')