Skip to content

Instantly share code, notes, and snippets.

@ywchiu
Created September 18, 2015 17:28
Show Gist options
  • Save ywchiu/0f78bc9ccf3864207ecb to your computer and use it in GitHub Desktop.
Save ywchiu/0f78bc9ccf3864207ecb to your computer and use it in GitHub Desktop.
import requests
from bs4 import BeautifulSoup
import base64
payload = {}
res = requests.get('http://www.twse.com.tw/ch/trading/exchange/BWIBBU/BWIBBU_d.php')
res.encoding = 'big5'
soup = BeautifulSoup(res.text)
for input_tag in soup.select('input'):
if input_tag.get('type') == 'hidden':
payload[input_tag.get('name')] = base64.b64encode(input_tag.get('value').encode('utf-8'))
#print payload['html']
res2 = requests.post('http://www.twse.com.tw/ch/trading/exchange/BWIBBU/BWIBBU_print.php?language=ch&save=csv', data=payload, stream=True)
from shutil import copyfileobj
f = open('export2.csv', 'wb')
copyfileobj(res2.raw, f)
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment