Skip to content

Instantly share code, notes, and snippets.

@ywchiu
Created January 13, 2015 08:13
Show Gist options
  • Save ywchiu/d726e0d042031a10bf10 to your computer and use it in GitHub Desktop.
Save ywchiu/d726e0d042031a10bf10 to your computer and use it in GitHub Desktop.
import requests
import json
url ="http://www.gretai.org.tw/web/stock/aftertrading/daily_trading_info/st43_result.php?l=zh-tw&d=%s&stkno=3290&_=1421136081459"
dt = "104/1"
from datetime import timedelta
from dateutil.relativedelta import relativedelta
getyear = dt.split('/',1)
bctime = str(int(getyear[0]) + 1911) +"/"+ getyear[1]
for i in range(1,10):
ts = (datetime.strptime(bctime, "%Y/%m") - relativedelta(months=i)).strftime("%Y/%m")
ts2 = ts.split('/',1)
ts3 = str(int(ts2[0]) - 1911) + '/' + ts2 [1]
res = requests.get(url %(ts3))
j = json.loads(res.text)
for price in j['aaData']:
print price[0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment