pythonpython-3.xbeautifulsouprequestmechanicalsoup

How to Load a page in python?


I need to just load my login page with my credentials entered. I was able to enter the login details and submit using MechanicalSoup My login page says in chrome browser:

Note : Do not close this window, closing this window will log you out.

How can I load the website and hold so, I won't get logged out. For instance,

import mechanicalsoup
browser = mechanicalsoup.StatefulBrowser()

try:
    browser.open("http://172.16.16.16:8090/")  # starting of login site
except:
    print('No connection to Login Page')
    exit()

This will just load my login page(http://172.16.16.16:8090') but will not keep it load. So, login will be disconnected after few time. How can I solve it?


Solution

  • In plain HTTP/HTML, "closing a page" does not do anything, so if the website you are browsing logs you out when you close a window, it most likely means that this website uses javascript (either to trigger an event on page close with beforeunload, or to periodically send a request to extend the session's duration). If so, then MechanicalSoup won't help much as it does not do JavaScript.

    See also: In MechanicalSoup (python 3x) how to logout a website whose logout button is a javascript and MechanicalSoup's FAQ