Search code examples
pythonhtmlurllib3

click submit button "OK" on a webpage using python requests module


i have a device that can be managed using webpage interface.

the device address can be :

http://10.18.25.25/restart

with a submit button in the webpage:

<form action="/restart/restart" method="POST" name="restartForm">
                            <input type="submit" value="OK">
                        </form>

i am trying to use python module requests to automate clicking on the button on that webpage.

from urllib3 import requests
r = requests.get('http://10.18.25.25/restart', auth=('username', 'password'))

any ideas??


Solution

  • From the info provided, I assume that you visit a page on http://10.18.25.25/restart/ which has a form, to restart your device on submit.

    The action you defined is present at URI /restart/restart on the form. So do a request on same URI:

    r = requests.post('http://10.18.25.25/restart/restart', auth=('username', 'password'))