Skip to main content

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

Comments

Popular Posts

Django static files not working when debug false || debug true

# Django static and media files not working when debug is false In this article you will learn how to fix problem of not loading static files and media in Django even the DEBUG is FALSE. This is the easiest and safest solution. # Problem: Django static and media files not working when debug is false  ➤ Code: settings.py DEBUG = False #True ALLOWED_HOSTS = [ '*' ] #Host name # Problem Fix: Let's see, How you can fix the problem of Django static and media files not working when DEBUB = False : 1.)First way: devserver in insecure mode If you still need to server static locally ( e.g. for testing without debug ) you can run devserver in insecure mode: python manage.py runserver --insecure --insecure: it means you can run serve

java program for student details using inheritance

# Java program to print student details using "single-level" inheritance In this section, You will learn how to print student details using single inheritance in java, with Scanner and without Scanner class. 1.) With " Scanner " class Let's try to create a simple example :   ➤ Example : student.java; import java.util.Scanner; class StudentDetails {    int roll_no ;    String name , cl ; //creating a function to take student details    void input () { Scanner sc = new Scanner ( System . in );   System . out . print ( "Ente

how to create enum in java

What is enum in Java? An enum is a special "data type" that used to create our own datatype like classes and It represents a group of constants (a variable that does not change). The enum is short for "enumerations", which means "specifically listed" and the Enum data also known as Enumerated Data Type. # Defining Java enum Instead of C/C++, in java programming language enum types are more powerful. Here, we can define an enum both inside and enum outside the class but not inside a Method "Rules" to defing enum in Java: To create an enum in Java, use the enum keyword (instead of class or interface) , and separate the constants with a comma (,) . The enum can be defined within or outside the class because it is similar to a class. The semicolon (;) at the end of the enum constants are optional Because enum are constants, the names of an enum type's fields are in uppercase letters.