[英]How to extract an hour from html code with python and beautiful soup
I am kinda new in Python and beautiful soup.我对 Python 和漂亮的汤有点陌生。 Can anyone help and answer how can I extract an hour from this html code?
任何人都可以帮助并回答我如何从这个 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>
Output should be: 12:20输出应该是:12:20
Thank you for all the answers in advance !感谢您提前提供所有答案!
You can try:你可以试试:
>>> 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'
Look at the Soup documentation and try to formulate an answer yourself first.查看Soup 文档并尝试先自己制定一个答案。 I would advise looking at
find_all('a')
and .text
functionalities for your example.我建议为您的示例查看
find_all('a')
和.text
功能。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.