Skip to content

Instantly share code, notes, and snippets.

@pjmavadiya
Created October 20, 2016 09:19
Show Gist options
  • Select an option

  • Save pjmavadiya/202a554b0c8d1abe3eb55f3773258d24 to your computer and use it in GitHub Desktop.

Select an option

Save pjmavadiya/202a554b0c8d1abe3eb55f3773258d24 to your computer and use it in GitHub Desktop.
Python : Determine last modified time of a web page
#!/usr/bin/python2.7
import requests
import sys
from urlparse import urlparse
#This will return last modified time of given web page url
def get_last_modified(url):
result = urlparse(url)
if True if [result.scheme, result.netloc, result.path] else False:
header = requests.head(url).headers
if 'Last-Modified' in header:
return header['Last-Modified']
print "Data is not available"
return -1
else:
return -1
#Demonstration of function call
if __name__ == '__main__':
try:
url = sys.argv[1]
print get_last_modified(url)
except Exception as e:
print "Please provide proper url as a first argument."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment