O'Reilly logo

Python Requests Essentials by Bala Subrahmanyam Varanasi, Rakesh Vidya Chandra

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Making a simple request

Now let us create our first request for getting a web page, which is very simple. The process includes importing the requests module, and then getting the web page with the get method. Let us look into an example:

>>> import requests
>>> r =  requests.get('http://google.com')

Voila! We are done.

In the preceding example, we get the google webpage, using requests.get and saving it in the variable r, which turns out to be the response object. The response object r contains a lot of information about the response, such as header information, content, type of encoding, status code, URL information and many more sophisticated details.

In the same way, we can use all the HTTP request methods like GET, POST, PUT, DELETE, HEAD with ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required