1

I've the following HTML code:

<html>
    <form action="index.php" method="post">
    Enter Input:
        <input type="text" class="textbox" name="usn" id="usn" required />
        <input  class="buttongo" type="submit" value="Go" />
        <input type="hidden" name="task" value="getResult"/>
    </form>
</html>

I want to write a python script, which executes the above HTML, passing a value parameter to the first input statement to the above HTML. That is,

<html>
    <form action="index.php" method="post">
    Enter Input:
        <input type="text" class="textbox" name="usn" id="usn" value="FromPython" />
        <input  class="buttongo" type="submit" value="Go" />
        <input type="hidden" name="task" value="getResult"/>
    </form>
</html>

Further, is there a way in which I can directly send the value to index.php and get the response?

(P.S.: I want to loop the value from 0 to 100 and save the response generated in a file)

2
  • please post what you have tried so far. Commented Jan 15, 2015 at 13:26
  • Think of using %s in your code or try considering .format() function Commented Jan 15, 2015 at 13:33

2 Answers 2

2

Why don't you send the request using python ? You can send the requests inside a loop and pass the parameters you want.

Making requests with the requests module

sample code :

import requests

for i in range(101):
    payload = {'usn': i}
    response = requests.post("index.php", data=payload)
    # do something with response
Sign up to request clarification or add additional context in comments.

3 Comments

its better to include the relevant code in your answer, if that website you linked goes down, your answer becomes useless.
Thanks @zxzak. Can you just explain a bit more how do I play with the response generated? can I use it as a string? I tried print(response), but that doesn't work.
I got it, used response.text.
2

Use urllib module, documentation at: https://docs.python.org/2/library/urllib.html

As described in the link, this module provides a high-level interface for fetching data across the World Wide Web.

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.