I have a simple html form (postform.html) which takes in two user inputs and passes them to a php file (post.php). The php file then echoes a string containing the user inputs.
I am running this from a local host and the code for the form is shown below:
<form action = "post.php" method = "post">
Name <input type = "text" name = "user"><br />
Company <input type = "text" name = "comp"> <br />
<input type = "submit" value = "Submit Info">
</form>
I would like to, using the Python requests module, post information into postform.html, and then retrieve the source code for the resulting echo. I have tried the following in Python command prompt after importing the requests module:
>>> data = {'user': 'Bob', 'comp': 'Walmart'}
>>> r = requests.post("http://localhost/practice/SimpleForm/postform.html",data)
>>> print(r.text)
<html>
<head><title> Post Method in Action </title></head>
<body>
<form action = "post.php" method = "post">
Name <input type = "text" name = "user"><br />
Company <input type = "text" name = "comp"> <br />
<input type = "submit" value = "Submit Info">
</form>
</body>
<html>
As you can see the text returned by the variable is the original html containing the form which is not what I want, I am trying to post information to the form and retrieve the source html for the result (post.php).
In some ways my question is similar to Python: How to send POST request? but not the same since this is a much simpler and more straightforward example of how to apply the requests.post function in Python. I have tried implementing the solution in the above thread but again only got the text for the original html.