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

标签 python beautifulsoup python-requests

不知道 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.xbtnSearch.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/

相关文章:

python - 仅对 numpy 中的前两个值求和

Python:从 FTP 服务器下载文件

python - Web抓取python : IndexError: list index out of range

python - 如何获取使用 JavaScript 构建的 anchor 标记的重定向链接?

python - 请求 - 多个代理 python

python - subprocess.Popen 令人困惑

python - 添加Conv1D层时出现错误 'Input 0 is incompatible with layer conv1d_48: expected ndim=3, found ndim=2'

python - 将 numpy 数组列表合并到一个数组中(快速)

python - 如何将 beautifulsoup 文本转换为列表或可迭代对象

python - 我怎样才能找到图片中突出显示的元素。我用 Selenium