Created
October 5, 2015 14:28
-
-
Save ywchiu/b94b2d85c2272f95762e 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 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, | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment