简体   繁体   English

我正在尝试使用python通过请求将数据提交到网站。 如何通过确认对话框?

[英]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. 我认为我没有选择适当的元素。

My Python code 我的Python代码

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)

HTML code of the receiving app - javascript 接收应用的HTML代码-javascript

<script>
function confirmSubmit()
{
var agree=confirm("Are you sure you wish to continue?");
if (agree)
    return true ;
else
    return false ;
}
</script>

HTML code of the receiving app - html content 接收应用的HTML代码-html内容

<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.

相关问题 仅从网站获取 JSON 的一部分,我正在尝试使用 Python、BeautifulSoup、请求来抓取。 从 62 条回复中获得 20 条回复 - Only getting a portion of JSON from website I am trying to scrape using Python, BeautifulSoup, Requests. Getting 20 responses out of 62 我正在尝试使用 python 从该网站下载年度数据,但我不知道如何处理它? - I am trying to download the Yearly data from this website using python but i am not sure how to approach it? 我正在尝试为scrapy请求打印301状态。 但是,页面重定向并每次显示200 - I am trying to print the 301 status for scrapy requests. But, the page redirects and shows 200 everytime 我正在尝试使用 beautifulsoup4 抓取网站并请求库 - I am trying to scrape a website using beautifulsoup4 and requests library 使用python中的requests函数将数据提交到网站并回调响应 - Using requests function in python to submit data to a website and call back a response Python请求。 如何保持登录状态? - Python requests. How to stay logged in? 尝试使用 Python 请求在 Oanda 上下订单。 获取 JSON 错误 - Trying to place an order on Oanda using Python Requests. Getting JSON error 错误 429,请求过多。 当我试图让我的 python discord 24/7 重复时 - Error 429, Too many requests. When I was trying to keep my python discord 24/7 on replit 我无法使用发布请求 python 登录网站 - I am not able to log in into a website using post requests python 我正在尝试使用 python 请求为网页抓取创建 POST 数据 - I am trying to create POST data for web scraping using python requests
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM