'Python requests POST with login credentials and form action=

I am trying to automate logging into my cable modems page and scrapping up some information so I can debug dropped internet connections. My Motorola modem's web page is accessed from my local network through this IP address:

https://192.168.100.1

which takes me to:

https://192.168.100.1/Login.html

The browser warns that it is not secure. Ignoring the warning and proceeding anyways gets me to my the login page for the modem. After logging in, I can see various status and log tables that I want to "scape" up and accumulate over time.

I am trying to use requests to login to the modem, then, in the same session access one of the pages. Here is my code:

# URL of my cable modem (same for all modems) - tried these combinations  
LOGIN_URL1 = "https://192.168.100.1/Login.html"  
LOGIN_URL2 = "https://192.168.100.1/cgi-bin/moto/goform/MotoLogin"
LOGIN_URL3 = "https://192.168.100.1/cgi-bin/moto/goform/MotoLogin/frmLogin"

# status pages reachable once logged in
MotoStatusConnection = "https://192.168.100.1/MotoStatusConnection.html"
MotoStatusSoftware = "https://192.168.100.1/MotoStatusSoftware.html"
MotoStatusLog ="https://192.168.100.1/MotoStatusLog.html"

# Default username and password for motorola cable modems - I've changed it :) 
payload = {
    'loginUsername': 'admin',
    'loginPassword': 'motorola',  # default password, I've changed it.
}

# Initiate a post session with login,  then try to get data from a page.
with requests.Session() as s:
    
    # Login into the page
    p = s.post(LOGIN_URL2, data=payload, verify=False)
    print(p.status_code,'\n')
    print(p.text, '\n')
    print(p.headers,'\n')
    
    print('***************************************************************************')

    # Try to get info from another page once logged in
    r = s.get(MotoStatusSoftware, verify=False)
    print(r.text)

And below images is the source of the modem's login page. I think I am not making the proper URL, and need to properly use the "form action=" and the "name=" somehow... or something else?

PS: output of first three prints is consistently:

200

{ "moto/goform/MotoLoginResponse": { "moto/goform/MotoLoginResult": "UN-AUTH" } }

{'Content-type': 'text/html', 'Strict-Transport-Security': 'max-age=60;includeSubdomains', 'X-Frame-Options': 'DENY', 'Cache-Control': 'no-store, no-cache, must-revalidate', 'Pragma': 'no-cache', 'set-cookie': 'Secure; HttpOnly', 'X-XSS-Protection': '1; mode=block', 'X-Content-Type-Options': 'nosniff', 'Content-Security-Policy': "default-src 'self' 'unsafe-inline' 'unsafe-eval'", 'X-Permitted-Cross-Domain-Policies': 'none', 'Content-Length': '86', 'Date': 'Mon, 21 Mar 2022 19:13:48 GMT'}

Thanks in advance for any help!

enter image description here

enter image description here

enter image description here



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source