我如何用Python正则表达式提取它?

时间:2015-07-25 17:31:47

标签: python regex web-scraping beautifulsoup

我试图将日期时间拉出:

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

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

1 个答案:

答案 0 :(得分:0)

使用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)