How to get all the content of a page?

Python 3: Can I get a webpage header information without get page content?

  • I know that if I send a http request to some website, I will got http header information back and http content,  and I wonder if I can only get the header information without get content for  a low network speed. (using python3 language is  appreciate, If some python3 package can do that , tell me the module name is OK)

  • Answer:

    Yes, this is the http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.4 HTTP verb. In Python 3, you can do a HEAD request using the http.client module (note: in Python 2, it’s called httplib): >>> from http import client >>> conn = client.HTTPConnection( "www.quora.com" ) >>> conn.request( "HEAD", "/Zhang-Peipei" ) >>> res = conn.getresponse() >>> print( res.status, res.reason ) 403 Forbidden >>> print( res.getheaders() ) [('Cache-Control', 'no-cache'), ('Content-Type', 'text/html'), ('Connection', 'keep-alive')] >>> res.read() b'' # there is no body, only headers Documentation: http://docs.python.org/3.0/library/http.client.html

Baptiste Fontaine at Quora Visit the source

Was this solution helpful to you?

Other answers

The easiest thing in Python is using the excellent Requests library: http://docs.python-requests.org/en/latest/ import requestsr = requests.head("http://httpbin.org/get")

Daniel Chvatik

import requests header_info = requests.head("http://www.example.com")

Eswar Yaganti

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.