Created
September 18, 2015 17:28
-
-
Save ywchiu/0f78bc9ccf3864207ecb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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