Getting file timestamp from url
Gabriel Genellina
gagsl-py2 at yahoo.com.ar
Sat Nov 17 04:07:12 EST 2007
En Fri, 16 Nov 2007 22:34:13 -0300,
mhearne808[insert-at-sign-here]gmail[insert-dot-here]com
<mhearne808 at gmail.com> escribió:
> Is is possible to get the timestamp of a file on a web server if it
> has a URL?
>
> For example, let's say that I want to know when the following file was
> created:
>
> http://www.w3schools.com/xml/note.xml
>
> I can get an HTTPMessage object using urllib2, like this:
>
> -------------------------------------------------------------------
> #!/usr/bin/python
> import urllib2
> url = 'http://www.w3schools.com/xml/note.xml'
> f = urllib2.urlopen(url)
> finfo = f.info()
> -------------------------------------------------------------------
>
> My finfo is an HTTPMessage object, which has getdate() and
> getdate_tz() methods. However, they both require a 'name' argument.
> I can't figure out what this is...
The documentation for urlopen
<http://docs.python.org/lib/module-urllib2.html> says that info() returns
a dictionary-like object. Try using keys() to see the available keys:
among others, you should see 'last-modified' (for objects that provide it;
it's not a mandatory header). The 'name' argument is precisely that: the
name of the header you want parsed as a date.
> Am I going down the wrong path? Is there a path I can go down to get
> what I want?
In short, you want finfo.getdate('last-modified')
--
Gabriel Genellina
More information about the Python-list
mailing list