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
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:
- Can I get a cellular phone online without a credit card?Best solution by Yahoo! Answers
- How can I get a loan without a job?Best solution by Yahoo! Answers
- Can I get a medical transcription job without the official training?Best solution by answers.yahoo.com
- How can I get into a graduate program without a stellar GPA?Best solution by answers.yahoo.com
- How can I get a text alert when I get an email?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
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.