Skip to content

Instantly share code, notes, and snippets.

@shihyu
Forked from ywchiu/BWIBBU_d.py
Created April 26, 2016 14:27
Show Gist options
  • Save shihyu/216f1e1bb60b06ee287918a7bc98a443 to your computer and use it in GitHub Desktop.
Save shihyu/216f1e1bb60b06ee287918a7bc98a443 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