Skip to main content
 首页 » 编程设计

python之不知道发布搜索按钮的 btnSearch.x 和 btnSearch.y 值

2024年12月31日8lori

不知道 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)