Ankaj Gupta
August 31, 2020
How to calculate content-length python

# Python requests calculate content length

In this section, we'll create a simple "content-length" calculate program in python. Let's follow the following steps and get content-length of your web page:

Step 1 : It is very important to install python requests module / package(eg : pip install requests).

  • pip install requests # for window

  • OR

  • pip3 install requests # for max, linux

Step 2 : After installing the request package, To verify the installation, you can try to import it like below:

  • import requests

Note : If you don't receive any errors importing the requests module, then it was successful installed.

Step 3 : Now, You can use 'GET request' to retrieve data from any destination

Let's create the simple example :

  ➤ Example : length.py

  1. import requests

  2. response = requests.get('https://www.google.com')

  3. #Just take the len() of the content of the response:

  4. content_len= len(response.content)

  5. print(content_len)

Output :
14227
Python programming