Python 中的`document.lastModified`
`document.lastModified` in Python
在python中,通过使用HTML解析器,是否可以获取网页的document.lastModified
属性。我正在尝试检索所有者最后修改 webpage/document 的日期。
一个有点相关的问题“I am downloading a file using Python urllib2. How do I check how large the file size is?”表明以下(未经测试的)代码应该有效:
import urllib2
req = urllib2.urlopen("http://example.com/file.zip")
total_size = int(req.info().getheader('last-modified'))
您可能希望将默认值添加为 getheader()
的第二个参数,以防未设置。
您还可以在 HTML 代码中查找 last-modified
日期,尤其是在 meta
标签中。 htmldate 模块就是这样做的。
这是它的工作原理:
1.安装包:
pip/pip3/pipenv (your choice) -U htmldate
2。检索网页,解析它并输出日期:
from htmldate import find_date
find_date('http://blog.python.org/2016/12/python-360-is-now-available.html')
(免责声明:我是作者)
在python中,通过使用HTML解析器,是否可以获取网页的document.lastModified
属性。我正在尝试检索所有者最后修改 webpage/document 的日期。
一个有点相关的问题“I am downloading a file using Python urllib2. How do I check how large the file size is?”表明以下(未经测试的)代码应该有效:
import urllib2
req = urllib2.urlopen("http://example.com/file.zip")
total_size = int(req.info().getheader('last-modified'))
您可能希望将默认值添加为 getheader()
的第二个参数,以防未设置。
您还可以在 HTML 代码中查找 last-modified
日期,尤其是在 meta
标签中。 htmldate 模块就是这样做的。
这是它的工作原理:
1.安装包:
pip/pip3/pipenv (your choice) -U htmldate
2。检索网页,解析它并输出日期:
from htmldate import find_date
find_date('http://blog.python.org/2016/12/python-360-is-now-available.html')
(免责声明:我是作者)