【问题标题】:How would I extract this with Python regular expressions?我将如何使用 Python 正则表达式提取它?
【发布时间】:2015-10-16 05:32:27
【问题描述】:

我正在尝试从以下位置提取日期时间:

<time datetime="2015-07-25T10:06:46-0700">2015-07-25 10:06am</time>

任何帮助将不胜感激,谢谢!

【问题讨论】:

标签: python regex web-scraping beautifulsoup


【解决方案1】:

使用BeautifulSoup解析器。

>>> html = '''<time datetime="2015-07-25T10:06:46-0700">2015-07-25 10:06am</time>'''
>>> from bs4 import BeautifulSoup
>>> soup = BeautifulSoup(html)
>>> soup.findAll('time')[0].text
'2015-07-25 10:06am'

re

re.search(r'<time\b[^>]*>([^<>]*)</time>', s).group(1)

【讨论】:

  • 我知道如何用 BeautifulSoup 做到这一点,我正在尝试用 re 做到这一点。
猜你喜欢
  • 1970-01-01
  • 2013-04-04
  • 2017-02-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-04-21
  • 2013-01-04
相关资源
最近更新 更多