我有一个具有机械导航外部网站的Python脚本。该网站显然是用ASP.NET编写的,使用的是动态控件。我试图模拟XHR来加载控件(通常通过单击<button>来触发),但是每当我执行XHR时,ASP服务器都会返回一个500个错误。我匹配通常发送的POST请求的有效负载。
基本上,我在做这个:
browser = mechanize.Browser()
browser.open('https://external.site/page.html')
# Here would be code to parse the content and extract the
# parameters for the XHR.
# Now we're making the XHR to update the control:
body = urllib.parse.urlencode({
'request': {
'control': 'Control_Name',
'parameters': parameters,
}
})
request = mechanize.Request(
url='https://external.site/server.asmx/LoadControl',
data=body,
method='POST',
)
response = browser.open(request)当我这样做时,浏览器会引发一个异常,因为它从服务器收到了一个500。
这可能是不可能的,因为一个CORS检查或类似的东西,但我觉得我只是没有提出正确的请求。当我在浏览器中使用外部网站时,URL和数据有效负载匹配通常发送的内容。
有没有办法通过机械化提出LoadControl请求?
作为参考,我试图浏览的网站上的按钮如下所示:
<button type="button"
data-focus="{"LoadParams":{"ControlName": [lots of key/value pairs here here]"}}"
data-action="GB.LoadControl">Button</button>当我单击该按钮时,XHR将包含以下有效负载:
{
"request": {
[the data here matches data-focus from the button]
}
}以及请求头:
POST /MyService.asmx/LoadControl HTTP/1.1
Host: myservice.com
Connection: keep-alive
Content-Length: 367
Accept: application/json, text/javascript, */*; q=0.01
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (X11; CrOS x86_64 12871.23.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.31 Safari/537.36
Content-Type: application/json; charset=UTF-8
Origin: https://myservice.com
Sec-Fetch-Site: same-origin
Sec-Fetch-Mode: cors
Sec-Fetch-Dest: empty
Referer: https://myservice.comService.aspx?AGU=1&[...]
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9,de-DE;q=0.8,de;q=0.7
Cookie: BIGipServerSD_Home=224813834.20480.0000; ASP.NET_SessionId=152i5tiwq1r2cbiuamxxxxxx; PVUE=00发布于 2020-02-29 03:28:42
https://stackoverflow.com/questions/58897051
复制相似问题