以下是我試著用綠茶妹之前分享的代碼修正要去下戴外資與陸資投資類股持股率表並存成csv檔
但發現下載下來的全都是空檔@@"
不知道是那邊有問題,需要請教各位資深的前輩唷!!
-
- from urllib import urlretrieve
- from datetime import date
- from datetime import datetime, timedelta
- #today = date.today().strftime('%Y_%m_%d')
- today = datetime.today()
- yesterday=today
- for daynum in range(1, 3521):
- path = yesterday.strftime('%Y_%m_%d')
- name = 'MI_QFIIS_cat-'+path+'.csv'
- print name
- try:
- urlretrieve('http://www.twse.com.tw/ch/trading/fund/MI_QFIIS_cat/MI_QFIIS_cat_print.php?language=ch&save=html&save=csv', 'E:\\MI_QFIIS_cat\\'+name)
- except IOError as IOE :
- print 'fault'
- except ContentTooShortError('!!',50) as CE:
- print 'too short'
- yesterday = yesterday - timedelta(1)
複製代碼 |