[英]Using python i am trying to submit data to a website via requests. How to pass the confirmation dialog?
I am logging into a site using Python and Requests. 我正在使用Python和Requests登录到站点。 Upon logging in there is a .asp page lets say import.asp where I am sending some data (via POST) using Requests again.
登录后,有一个.asp页,请说import.asp,我将再次使用Requests通过POST发送一些数据(通过POST)。 Once this data is sent and submitted there is a popup asking me to confirm if I want to proceed ahead.
发送并提交此数据后,会弹出一个窗口,要求我确认是否要继续进行。 I want to click the 'OK' button.
我要点击“确定”按钮。
I have tried Selenium and I keep getting 'element not found' error. 我尝试了Selenium,但不断收到“找不到元素”错误。 I think I am not choosing the proper elements.
我认为我没有选择适当的元素。
url1 = "hxxp://site.com/login.asp"
url2 = "hxxp://site.com/import.asp"
headers = {'Content-type': 'application/x-www-form-urlencoded'}
payload1 = {'username': 'abc','password': '123'}
payload2 = {'signature':sig_test,informational':'off','comment':'testing333'}
s = requests.Session()
#Logging in
r = s.post(url1, data=payload, headers=headers)
#Posting data
r2 = s.post(url2, json.dumps(payload2), headers=headers)
<script>
function confirmSubmit()
{
var agree=confirm("Are you sure you wish to continue?");
if (agree)
return true ;
else
return false ;
}
</script>
<form name="myform" method="POST" action="import.asp" onsubmit="document.myform.data.value=escape(document.myform.data.value);return confirmSubmit();"/>
<label><b>Signature:</b></label><br />
<textarea name="signature" cols="85" rows="10"></textarea><br>
<label><b>Comment:</b></label><br />
<textarea name="comment" cols="85" rows="10"></textarea><br>
<input type="checkbox" name="informational"> Info
<input type="submit" name="submit" value="Import Signatures">
</form>
I expect the data to pass through and give me confirmation which I receive when I actually do this on the website. 我希望数据能够传递并给我确认,当我在网站上实际进行确认时,我会收到此确认。
If you're using requests you aren't going to be interacting with any javascript. 如果您使用请求,则不会与任何javascript进行交互。 The code that you show doesn't seem to indicate anything meaningful to you happens when yes is clicked anyway.
当您单击“是”时,显示的代码似乎并不表示对您有意义的任何事情发生。 Use developer tools in chrome or firefox to manually log into the website and inspect all of the requests that are actually sent to the server.
使用chrome或firefox中的开发人员工具手动登录网站并检查实际发送到服务器的所有请求。 If you duplicate them you should be able to get in. The javascript is only used in the creation of these requests unless there is something more complicated like a websocket which there doesn't seem to be.
如果您复制它们,则应该可以使用。javascript仅在创建这些请求时使用,除非存在诸如websocket之类的更复杂的东西(似乎没有)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.