Skip to content

Instantly share code, notes, and snippets.

@flyakite
Created February 16, 2016 15:31
Show Gist options
  • Save flyakite/0bfc413120795a71e646 to your computer and use it in GitHub Desktop.
Save flyakite/0bfc413120795a71e646 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