Getting file timestamp from url

  • Thread starter mhearne808[insert-at-sign-here]gmail[insert-dot-he
  • Start date
M

mhearne808[insert-at-sign-here]gmail[insert-dot-he

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...

Am I going down the wrong path? Is there a path I can go down to get
what I want?

Thanks,

Mike
 
G

Gabriel Genellina

En Fri, 16 Nov 2007 22:34:13 -0300,
mhearne808[insert-at-sign-here]gmail[insert-dot-here]com
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')
 
T

Tim Roberts

"mhearne808[insert-at-sign-here]gmail[insert-dot-here]com"
Is is possible to get the timestamp of a file on a web server if it
has a URL?

No, not in the general case.
For example, let's say that I want to know when the following file was
created:

http://www.w3schools.com/xml/note.xml

Remember that the only information that you get back from the server is the
HTTP request. There is a "Last-Modified" header in the HTTP standards that
says when the page was last modified, and Apache is good about sending it,
but that's all you can find out. Plus, remember that web proxies can
interfere with this.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top