不知道btnSearch.x和btnSearch.y的值,用于发布搜索按钮以单击具有以下参数的搜索按钮吗?
payload={
'today':'20180806'
'sortBy':'',
'alertMsg':'',
'ddlShareholdingDay':'04',
'ddlShareholdingMonth':'06',
'ddlShareholdingYear':'2018',
'btnSearch.x':'????',
'btnSearch.y':'???'
}
import requests
from bs4 import BeautifulSoup
html = "url"
r=requests.post(html, data=payload)
c=r.content
soup=BeautifulSoup(c,"html.parser")
all_tables=[[td.text for td in tr.find_all('td')] for tr in
soup.find_all('table')[2].find_all('tr')]
stock_info=[[sub_item.replace('\r\n', '') for sub_item in item] for item in all_tables]
for stock in stock_info[2:]:
print stock
最佳答案
btnSearch.x
和btnSearch.y
值并不重要,它们只是btnSearch
图像的鼠标坐标(我认为),并且对POST请求没有任何影响。
但是,ASP.NET Web应用程序使用一些重要的隐藏字段(__VIEWSTATE
,__EVENTVALIDATION
)。我们可以找到这些值,然后将它们与POST数据一起提交。
import requests
from bs4 import BeautifulSoup
url = 'url'
s = requests.session()
r = s.get(url)
soup = BeautifulSoup(r.text, 'html.parser')
data = {i['name']: i.get('value') for i in soup.select('input')}
data['ddlShareholdingDay'] = '04'
data['ddlShareholdingMonth'] = '06'
data['ddlShareholdingYear'] = '2018'
data['btnSearch.x'] = '????'
data['btnSearch.y'] = '???'
r = s.post(url, data)
soup = BeautifulSoup(r.text, 'html.parser')
stock_info = [
[td.text.strip() for td in tr.find_all('td')]
for tr in soup.find_all('table')[2].find_all('tr')
]
for stock in stock_info[2:]:
print(stock)
关于python - 不知道发布搜索按钮的btnSearch.x和btnSearch.y值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/51702498/