Created
October 20, 2016 09:19
-
-
Save pjmavadiya/202a554b0c8d1abe3eb55f3773258d24 to your computer and use it in GitHub Desktop.
Python : Determine last modified time of a web page
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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