我正在使用python脚本从一些出版商的网站上抓取文章的发布日期。该数据可在HTML属性或标记中找到,这些属性或标记由“时间”、“时间戳”和“发布日期”等标识,并以以下格式提供时间:
<time class="timestamp article__timestamp flexbox__flex--1"> Updated Aug. 18, 2021 3:54 pm ET </time>
<time class="css-x7rtpa e16638kd0" datetime="2021-08-18T19:10:54-04:00">Aug. 18, 2021</time>
<time datetime="2021-08-18T15:45:33-04:00"><span class="date">August 18, 2021</span><span class="time">3:45 PM ET</span></time>
<div class="timestamp"><span aria-label="Published on August 19, 2021 12:36 AM ET" class="timestamp__date--published"><span aria-hidden="true">08/19/2021 12:36 am ET</span></span></div>
<div class="article-date"><strong>Published</strong> <time> 8 hours ago</time></div>
'published_time': '2021-08-18T05:33:59Z
这就是我从这些HTML标记中获取这些日期后,这些日期的文本通常的样子:
Aug. 18, 2021 6:56 am ET
Aug. 18, 2021
Updated Aug. 18, 2021 3:54 pm ET
Published 6 hours ago
2021-08-18T08:00:00Z
我计划在将来抓取更多出版商的网站,所以在我编写自己的脚本之前,我很好奇是否有一个现有的解决方案或框架可以统一这种格式
上面的标记和结果文本没有以1:1的关系显示,因为有足够多的变化,除了编写我自己的脚本之外,这对于解决方案来说有些无关紧要。到目前为止,我找到的解决方案都引用Javascript中的统一日期,但在从HTML标记提取时却没有
这些日期最终将由Swift编写的服务器应用程序使用
dateparserpython库看起来是满足我需求的最佳解决方案
为了实现长期稳定性,始终要考虑生产部署:
相关问题 更多 >
编程相关推荐