Shery
Shery

Reputation: 1882

Extract text from class 'bs4.element.Tag' beautifulsoup

I have the following text in a class 'bs4.element.Tag' object:

<span id="my_rate">264.46013</span>

How do I strip the value of 264.46013 and get rid of the junk before and after the value?

I have seen this and this but I am unable to use the text.split() methods etc.

Cheers

Upvotes: 0

Views: 232

Answers (1)

Barry the Platipus
Barry the Platipus

Reputation: 10460

I'm not sure I follow, however, if you are using BeautifulSoup:

from bs4 import BeautifulSoup as bs

html = '<span id="my_rate">264.46013</span>'

soup = bs(html, 'html.parser')
value = soup.select_one('span[id="my_rate"]').get_text()
print(value)

Result:

264.46013

Upvotes: 2

Related Questions