Python: Login to a webpage and click a button without Selenium

I am writing a python script to connect to a website, login and click a button at the moment on the next page. I was able to do this with Selenium, but I would like to get a solution without having to open a browser.

I am trying to do this with queries. I can login and go to the secure page, but I am struggling to click the button:

import requests

payload = {
    'username': 'MyUsername',
    'password': 'MyPassword'
}

with requests.Session() as s:
    p = s.post("login_URL", data=payload)
    print (p.text)

    r = s.get("A_protected_URL")
    print (r.text)

      

The button that I would like to click is in "A_protected_URL" and is defined as follows:

<script type="text/javascript">
function SubmitForm(form) // Button clicked
{
    form.Submit.disabled = true;
    form.Submit.value = "Please wait...";
    return true;
 }
</script>
<div id="submit_button" >
<form action="https://mydummywebsite.com/submitted" 
 method="post" onsubmit="return SubmitForm(this);" >
<input type="submit" class="sub-process-button" name="Submit" value="Submit">
</form>

      

What is the correct way to send a request to a button that executes Javascript? Thanks to

+3


source to share





All Articles