Reputation: 4136
Is there a way to find out how much time has passed since a web page was changed?
For example,
I have a page hosted at: www.mywebsitenotupdated.com
Is there a way to find out when this HTML page was uploaded to the server?
I have no access to server; just a link to the webpage.
Upvotes: 80
Views: 196159
Reputation: 201866
No, you cannot know when a page was last updated or last changed or uploaded to a server (which might, depending on interpretation, be three different things) just by accessing the page.
A server may, and should (according to the HTTP 1.1 protocol), send a Last-Modified
header, which you can find out in several ways, e.g. using Rex Swain’s HTTP Viewer. However, according to the protocol, this is just
“the date and time at which the origin server believes the variant was last modified”.
And the protocol realistically adds:
“The exact meaning of this header field depends on the implementation of the origin server and the nature of the original resource. For files, it may be just the file system last-modified time. For entities with dynamically included parts, it may be the most recent of the set of last-modify times for its component parts. For database gateways, it may be the last-update time stamp of the record. For virtual objects, it may be the last time the internal state changed.”
In practice, web pages are very often dynamically created from a Content Management System or otherwise, and in such cases, the Last-Modified
header typically shows a data stamp of creating the response, which is normally very close to the time of the request. This means that the header is practically useless in such cases.
Even in the case of a “static” page (the server simply picks up a file matching the request and sends it), the Last-Modified
date stamp normally indicates just the last write access to the file on the server. This might relate to a time when the file was restored from a backup copy, or a time when the file was edited on the server without making any change to the content, or a time when it was uploaded onto the server, possibly replacing an older identical copy. In these cases, assuming that the time stamp is technically correct, it indicates a time after which the page has not been changed (but not necessarily the time of last change).
Upvotes: 77
Reputation: 4699
This is a Pythonic way to do it:
import httplib
import yaml
c = httplib.HTTPConnection(address)
c.request('GET', url_path)
r = c.getresponse()
# get the date into a datetime object
lmd = r.getheader('last-modified')
if lmd != None:
cur_data = { url: datetime.strptime(lmd, '%a, %d %b %Y %H:%M:%S %Z') }
else:
print "Hmmm, no last-modified data was returned from the URL."
print "Returned header:"
print yaml.dump(dict(r.getheaders()), default_flow_style=False)
The rest of the script includes an example of archiving a page and checking for changes against the new version, and alerting someone by email.
Upvotes: 1
Reputation: 766
There is another way to find the page update which could be useful for some occasions (if works:).
If the page has been indexed by Google, or by Wayback Machine you can try to find out what date(s) was(were) saved by them (these methods do not work for any page, and have some limitations, which are extensively investigated in this webmasters.stackexchange question's answers. But in many cases they can help you to find out the page update date(s):
Saved 6 times between June 7, 2014 and November 23, 2016.
, and you can view all saved copies for each dateUpvotes: 18
Reputation: 2636
For me it was the
article:modified_time
in the page source.
Upvotes: 0
Reputation: 136735
For checking the Last Modified
header, you can use httpie
(docs).
pip install httpie --user
$ http -h https://martin-thoma.com/author/martin-thoma/ | grep 'Last-Modified\|Date'
Date: Fri, 06 Jan 2017 10:06:43 GMT
Last-Modified: Fri, 06 Jan 2017 07:42:34 GMT
The Date
is important as this reports the server time, not your local time. Also, not every server sends Last-Modified
(e.g. superuser seems not to do it).
Upvotes: 4