IHosseini
IHosseini

Reputation: 31

Get inner text in html tags with Beatifulsoup in python

I'm trying to get a inner text inside of a html tag with bs4 but i'm not familiar with the library. would be appreciated you guys help me 🙏🏻.

html:

<span class="course-time"> Duration<i> 3:1:00 </i></span>

for example I'm using this code to get the text inside of i tag:

duration = soup.findAll("span" , attrs = {"class" : {"course-time"}})[0].decode_contents()

when I use this code, i get the text but with i tag.

i just want the text.

how can i do so?

Upvotes: 2

Views: 309

Answers (1)

wasif
wasif

Reputation: 15470

You can just use .text:

duration = soup.findAll("span" , attrs = {"class" : {"course-time"}})[0].text

Upvotes: 2

Related Questions