[Python] Get the last updated date of the website

It can be rough. I want to know the update date of the site.

I want to sort the crawled sites in order of site update date, but I didn't know how to get the site update date so I looked it up.

reference

I want to get the time stamp of a file placed on the WEB with python. Posted on 2017/10/13 14:41 Last-Modified

The HTTP Last-Modified response header contains the date and time when the origin server determines that the resource was last modified. It is used as a validation material to determine if the received or stored resources are the same. It is less accurate than the ETag header and is an alternative.

Implementation

get_lastmodified.py


import requests
res = requests.head('https://www.kantei.go.jp')
print(res.headers['Last-Modified'])

import datetime
html_timestamp = datetime.datetime.strptime(res.headers['Last-Modified'], "%a, %d %b %Y %H:%M:%S GMT")
print(html_timestamp)

% python get_lastmodified.py
Mon, 17 Feb 2020 08:27:02 GMT
2020-02-17 08:27:02

It also converts the datetime to the standard format.

Postscript

This method is too weak for dynamic sites, so I thought about it a little more.

Get the site update date seriously

Recommended Posts

[Python] Get the last updated date of the website
Get the update date of the Python memo file.
Get the last day of the specified month
[Python] Get the character code of the file
Note: Get the first and last items of Python OrderedDict non-destructively
[Python] How to get the first and last days of the month
[Python] Get the update date of a news article from HTML
Get the title and delivery date of Yahoo! News in Python
[Python] Get / edit the scale label of the figure
[Python] Get the main topics of Yahoo News
Get the caller of a function in Python
Check the date of the flag duty with Python
[Python3] Get date diff
Get date in Python
Get date with python
[Python] Split the date
[Python] Get the day of the week (English & Japanese)
Note: How to get the last day of the month with python (added the first day of the month)
Get the last element of the array by splitting the string in Python and PHP
[Python] Get the official file path of the shortcut file (.lnk)
[Python] Get the text of the law from the e-GOV Law API
[python] Get the list of classes defined in the module
Get the return code of the Python script from bat
Get the size (number of elements) of UnionFind in Python
[Python] Get the list of ExifTags names of Pillow library
Get the operation status of JR West with Python
Script to get the expiration date of the SSL certificate
[Python] Get the number of views of all posted articles
Get the URL of the HTTP redirect destination in Python
Towards the retirement of Python2
Get last month in python
About the ease of Python
Get the number of digits
[Python] Get the previous month
About the features of Python
The Power of Pandas: Python
Try to get the function list of Python> os package
Get the number of specific elements in a python list
How to get the last (last) value in a list in Python
Get the current date and time in Python, considering the time difference
Google search for the last line of the file in Python
Get the index of each element of the confusion matrix in Python
Get the source of the page to load infinitely with python.
The story of Python and the story of NaN
Get the number of views of Qiita
[Python] The stumbling block of import
First Python 3 ~ The beginning of repetition ~
Get the desktop path in Python
Get the site update date seriously
Get the weather with Python requests
Get the weather with Python requests 2
pyenv-change the python version of virtualenv
Get the script path in Python
How to get the Python version
Get the attributes of an object
Change the Python version of Homebrew
Get the first element of queryset
[Python] Understanding the potential_field_planning of Python Robotics
Review of the basics of Python (FizzBuzz)
Get the number of Youtube subscribers
Get the desktop path in Python