Skip to content

Instantly share code, notes, and snippets.

@andy23512
Created December 29, 2017 12:00
Show Gist options
  • Save andy23512/af1e22ba577970c550096fb0331bdff1 to your computer and use it in GitHub Desktop.
Save andy23512/af1e22ba577970c550096fb0331bdff1 to your computer and use it in GitHub Desktop.
import pandas
from datetime import timedelta, date
def getstockdate(dayary):
[y, m, d] = dayary
url = ('https://www.taifex.com.tw/chinese/3/3_1_1.asp?qtype=2&commodity_id=TX&commodity_id2&market_code=0&goday&dateaddcnt=0'
+ '&DATA_DATE_Y=%d' % y
+ '&DATA_DATE_M=%d' % m
+ '&DATA_DATE_D=%d' % d
+ '&syear=%d' % y
+ '&smonth=%d' % m
+ '&sday=%d' % d
+ '&datestart=%d%%2F%d%%2F%d' % dayary
+ '&MarketCode=0&commodity_idt=TX&commodity_id2t&commodity_id2t2')
dfs = pandas.read_html(url)
currency = dfs[4]
print(dayary)
if currency.shape[0] > 1 and currency.shape[1] > 10:
currency = currency.iloc[1:2, [2, 3, 4, 5, 10]]
print(currency)
else:
print('no data at this day')
today = date.today()
for i in range(4):
day = today + timedelta(days=-i)
getstockdate(day.timetuple()[:3])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment