HTTP Get Variables In Python

Intro

In this blog, I am going to get HTTP variables in Python. I will create one HTML file and will show the requested keyword opened in the web browser. The HTTP URL shows in Python console screen.

Software requirement

Python 3.5 and IDE (Python 3.5)

Programming code

  1. #HTTP GET variables in Python  
  2. #import packages  
  3. import requests  
  4. #set parameter  
  5. params={"q":"apple"}  
  6. #request  
  7. r=requests.get("http://www.google.com",params=params)  
  8. #output statement  
  9. print("status",r.status_code)  
  10. print(r.url)  
  11. #open web browser  
  12. f=open("./page.html","w+")  
  13. f.write(r.text)  

About the code

First, I am importing the "requests" modules.

Next, setting the parameter and requesting the website code.

Next, using the output statement to print requested keyword URL in console.

Finally, I have written the code to show the HTTP and keyword in a web browser.

Then, let’s execute the code.

Output

 
 
Ebook Download
View all
Learn
View all