Skip to content

Instantly share code, notes, and snippets.

@shihyu
Forked from flyakite/twse.py
Created April 26, 2016 14:27
Show Gist options
  • Save shihyu/30fce05f8fee1712cae33aef5b5179c0 to your computer and use it in GitHub Desktop.
Save shihyu/30fce05f8fee1712cae33aef5b5179c0 to your computer and use it in GitHub Desktop.
import BeautifulSoup, requests
r=requests.post('http://www.twse.com.tw/ch/trading/exchange/BWIBBU/BWIBBU.php', {'STK_NO':2330, 'myear': 2016, 'mmon':2})
soup = BeautifulSoup.BeautifulSoup(r.content)
table = soup.find('table', {'class':'board_trad'})
with open('out2.csv', 'w') as f:
trs = table.findAll('tr')
for tr in trs:
tds = tr.findAll('td')
f.write(', '.join([td.text.encode('utf-8') for td in tds]) + '\n')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment