Posting Data In Python

Intro

In this blog, I am going show how to post data into a demo form in Python. It will post the user data into a demo form in the web browser.

Software requirement

Python 3.5 and IDLE (Python 3.5)

Programming code

  1. #Posting data in Python  
  2. #import packages  
  3. import requests  
  4. #post data  
  5. mydata={"name":"raj""email""[email protected]"}  
  6. #request  
  7. r=requests.post("https://www.w3schools.com/php/welcome.php", data=mydata)  
  8. #output statement  
  9. f=open("myfile.html","w+")  
  10. f.write(r.text)  

About the code

First, I am importing the requests modules.

Next, set posting data and request to demo form page.

Finally, I have written the output statement to show the result in a web browser.

Then, let’s execute the code.

Form

 
 
Before executing the code.
 
 
 
 After executing the code.
 
 
Ebook Download
View all
Learn
View all