【发布时间】:2023-01-09 03:04:24
【问题描述】:
我有一段 HTML,其中包含这样的日期时间
<time datetime="2023-01-06 05:00:00" data-format="article-display" data-show-date="always" data-show-time="today-only" data-timestamp="1672981200" itemprop="datePublished" class="author-details__timestamp formatTimeStampEs6" full-date="05.01.2023">6th January</time>
我使用了 Chrome 检查器中的副本 JS,并将其返回
#article > div.mar-article > div > div.mar-article__timestamp > time
def extract_time(data):
"""Extract the time from the HTML of the article page."""
soup = BeautifulSoup(data, 'html.parser')
# Use the select_one() method to find the time element
time_element = soup.find("time", class_="datetime")
print(time_element)
return time_element
为什么它返回无?
我很困惑,因为我不知道如何只返回日期时间。
【问题讨论】:
-
print(soup.find("time"))显示什么?
标签: html google-chrome beautifulsoup