【问题标题】:How to extract an hour from html code with python and beautiful soup如何用python和漂亮的汤从html代码中提取一个小时
【发布时间】:2020-04-05 23:10:36
【问题描述】:
我对 Python 和美丽的汤有点陌生。
任何人都可以帮助并回答我如何从这个 html 代码中提取一个小时?
<a class="hour-link fancybox-reservation" href="/47,Lodz/Seans/info/seans/CC527207-4B9C-45CD-812F-3501A647E1B3/dzien/146231/film/16892">12:20</a>
输出应该是:12:20
提前感谢您的所有回答!
【问题讨论】:
标签:
python
html
beautifulsoup
【解决方案1】:
你可以试试:
>>> from bs4 import BeautifulSoup as bs
>>> data = """<a class="hour-link fancybox-reservation" href="/47,Lodz/Seans/info/seans/CC527207-4B9C-45CD-812F-3501A647E1B3/dzien/146231/film/16892">12:20</a>"""
>>> soup = bs(StringIO(data))
>>> a_tag = soup.find_all('a')
>>> a_tag[0]
<a class="hour-link fancybox-reservation" href="/47,Lodz/Seans/info/seans/CC527207-4B9C-45CD-812F-3501A647E1B3/dzien/146231/film/16892">12:20</a>
>>> a_tag[0].text
'12:20'