Skip to content

Instantly share code, notes, and snippets.

@ywchiu
Created October 5, 2015 14:28
Show Gist options
  • Save ywchiu/b94b2d85c2272f95762e to your computer and use it in GitHub Desktop.
Save ywchiu/b94b2d85c2272f95762e to your computer and use it in GitHub Desktop.
import requests
from bs4 import BeautifulSoup as bs
rs = requests.session()
payload = {
'pageTypeHidden':'1',
'code':'1101',
'ctl00$ContentPlaceHolder1$DropDownList1':'2015年6月'
}
res = rs.get('http://www.cnyes.com/twstock/directorholder/1101.htm')
#print res.text
soup = bs(res.text)
hidden = soup.select('input')
for hid in hidden:
if hid.get('value') is not None and hid.get('value') != '':
payload[hid.get('name')] = hid.get('value')
res2 = rs.post('http://www.cnyes.com/twstock/directorholder/1101.htm', data= payload)
soup = bs(res2.text)
table = soup.select('.tabvl')[0]
for tr in table.select('tr')[1:]:
for td in tr.select('td'):
print td.text,
print
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment