Re: urllib, urlretrieve method, how to get headers?



Даниил Рыжков 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:

f = urllib2.urlopen("http://www.python.org";)
f.headers["Content-Type"]
'text/html'

Write page content to file:

with open("tmp.html", "w") as dest:
.... dest.writelines(f)
....

Did we get what we expected?

with open("tmp.html") as f: print f.read().split("title")[1]
....
Python Programming Language &ndash; Official Website</


.



Relevant Pages

  • Re: urllib, urlretrieve method, how to get headers?
    ... How can I get headers with urlretrieve? ... headers with necessary information before I execute urlretrieve(). ...
    (comp.lang.python)
  • urllib, urlretrieve method, how to get headers?
    ... How can I get headers with urlretrieve? ... headers with necessary information before I execute urlretrieve(). ...
    (comp.lang.python)
  • Re: Provide a link to a secure website from a WinForms application
    ... This opens the default browser but it doesn't logon the user automatically. ... I have to insert links to a third party website which has detailed information of that company. ... this website requires a username and password to logon. ... This website redirects to the third party website but I can't add the necessary stuff to the headers. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Zone Alarm 3.0 Some Bad News for web sites !
    ... HTTP Referer Headers have been used for a long time now for some basic ... concepts even within a website. ... Touted as a privacy issue, ... > and most important need for this field, is that this tells a web site ...
    (comp.security.firewalls)
  • Provide a link to a secure website from a WinForms application
    ... I have to insert links to a third party website which has detailed information of that company. ... We got a username and a password from the supplier and they gave us an URL with which we can login directly using a TVA-number as a parameter in the URL. ... This website redirects to the third party website but I can't add the necessary stuff to the headers. ... When I use a HttpWebRequest and a HttpWebResponse, ...
    (microsoft.public.dotnet.languages.csharp)