Re: urllib, urlretrieve method, how to get headers?
- From: Peter Otten <__peter__@xxxxxx>
- Date: Fri, 01 Jul 2011 09:43:03 +0200
Даниил Рыжков wrote:
How can I get headers with urlretrieve? I want to send request and get
headers with necessary information before I execute urlretrieve(). Or
are there any alternatives for urlretrieve()?
It's easy to do it manually:
import urllib2
Connect to website and inspect headers:
'text/html'f = urllib2.urlopen("http://www.python.org")
f.headers["Content-Type"]
Write page content to file:
.... dest.writelines(f)with open("tmp.html", "w") as dest:
....
Did we get what we expected?
....with open("tmp.html") as f: print f.read().split("title")[1]
Python Programming Language – Official Website</
.
- References:
- urllib, urlretrieve method, how to get headers?
- From: Даниил Рыжков
- urllib, urlretrieve method, how to get headers?
- Prev by Date: Re: urllib, urlretrieve method, how to get headers?
- Next by Date: Re: Trying to chain processes together on a pipeline
- Previous by thread: urllib, urlretrieve method, how to get headers?
- Next by thread: Re: urllib, urlretrieve method, how to get headers?
- Index(es):
Relevant Pages
|