2

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

2 Answers 2

3

Depending on the site you may or may not be able to emulate the form's action with an appropriate HTTP POST request to /request/request, but in the majority of real-world examples I have seen there are additional cookies and javascript that runs alongside the form making this approach extremely difficult if not impossible.

However, check out the Selenium library, which provides commands to operate a browser programatically via Python. I know your specific question is for the requests module, and in your case that may suffice perfectly, but in the general case Selenium might be worth checking out.

Sign up to request clarification or add additional context in comments.

Comments

2

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'))

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.