Python don';我不知道发布搜索按钮的btnSearch.x和btnSearch.y值

Python don';我不知道发布搜索按钮的btnSearch.x和btnSearch.y值,python,beautifulsoup,python-requests,Python,Beautifulsoup,Python Requests,不知道搜索按钮后的btnSearch.x和btnSearch.y值,以使用以下参数单击搜索按钮 payload={ 'today':'20180806' 'sortBy':'', 'alertMsg':'', 'ddlShareholdingDay':'04', 'ddlShareholdingMonth':'06', 'ddlShareholdingYear':'2018', 'btnSearch.x':'????', 'b

不知道搜索按钮后的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

我已经使用了
curl
,并且能够使用这个简化的请求获得结果:

$ curl 'url' \
-H 'User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:61.0) Gecko/20100101 Firefox/61.0' \
-H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8,application/pdf;q=0.1' \
-H 'Accept-Language: de-DE,de;q=0.8,en-US;q=0.5,en;q=0.3' --compressed \
-H 'Content-Type: application/x-www-form-urlencoded' \
--data 'today=20180806&ddlShareholdingDay=04&ddlShareholdingMonth=08&ddlShareholdingYear=2018&btnSearch.x=0&btnSearch.y=0'
请注意,此请求中没有cookie。两个
btnSearch
参数似乎是必需的,但我无法观察到不同值的任何影响。请求正文仅包含以下字段:

today=20180806
ddlShareholdingDay=04
ddlShareholdingMonth=08
ddlShareholdingYear=2018
btnSearch.x=0
btnSearch.y=0
使用Python和请求此类请求可能如下所示:

import requests

url = "url"
payload =  {
  "today": "20180806",
  "ddlShareholdingDay": "04",
  "ddlShareholdingMonth": "08",
  "ddlShareholdingYear": "2018",
  "btnSearch.x": "0",
  "btnSearch.y": "0"
}
response = requests.post(url, data=payload)

然后,您可以继续解析
response.content
,它是HTML主体。

btnSearch.x
btnSearch.y
值并不重要,它们只是
btnSearch
图像的鼠标坐标(我认为),对POST请求没有任何影响

但是,ASP.NET web应用程序使用了一些重要的隐藏字段(
\uuu VIEWSTATE
\uu 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)

在请求中不使用
有效负载
。你试过这么做吗?会发生什么?亲爱的,是的,我不知道如何应用有效负载来让请求查看。但是,当您单击搜索按钮时,还可以查看浏览器发出的POST请求的详细信息。请求正文包含一些我不理解的更多数据。请尝试
r=requests.post(html,data=payload)
单击按钮?!您正在发送HTTP请求-无法“单击”某些内容。。。如果你想进行真正的点击,你可以使用Selenium,例如耳朵,谢谢,但是当我更改“ddlShareholdingDay”:“31”,“ddlShareholdingMonth”:“01”,“ddlShareholdingYear”:“2018”,实际上没有任何更改,这意味着不发布任何日期、月份和年份的信息,只使用默认值。好吧,我认为您必须分析这个HTML表单的行为,并找出参数是如何工作的。我担心我们在这方面帮不了什么忙。也许你可以问运行这个网站的人是否有一个官方的API。也许它甚至会返回JSON之类的结构化数据,这样您就不必刮去HTML了。