1. 程式人生 > >Python語言:下載上證股票資料程式

Python語言:下載上證股票資料程式

from urllib.request import urlretrieve

f = open('SHA.csv', 'r')
for line in f:
data = line.split(',')
stock_no = '0' + data[0].strip()
start_date = data[1].strip().replace('-','')
url = 'http://quotes.money.163.com/service/chddata.html?code=' + stock_no + '&start=' + start_date + '&end=20181103&fields=TCLOSE;HIGH;LOW;TOPEN;LCLOSE;CHG;PCHG;TURNOVER;VOTURNOVER;VATURNOVER;TCAP;MCAP'
filename = stock_no + '.csv'
print(url)
urlretrieve (url, filename)