0

I am kinda new in Python and beautiful soup. Can anyone help and answer how can I extract an hour from this html code ?

<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

Thank you for all the answers in advance !

Shiny
  • 4,945
  • 3
  • 17
  • 33
Piotrek85
  • 3
  • 3
  • 1
    Does this answer your question? [BeautifulSoup innerhtml?](https://stackoverflow.com/questions/8112922/beautifulsoup-innerhtml) – Kevin Hernandez Dec 12 '19 at 14:33

2 Answers2

0

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'

abhilb
  • 5,639
  • 2
  • 20
  • 26
0

Look at the Soup documentation and try to formulate an answer yourself first. I would advise looking at find_all('a') and .text functionalities for your example.