0

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

Shery
  • 1,808
  • 5
  • 27
  • 51

1 Answers1

2

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
Barry the Platipus
  • 9,594
  • 2
  • 6
  • 30