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

Shery

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

Barry the Platipus

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to extract text from outside of tag with BS4

bs4 extract text from multiple spans in a tag

BeautifulSoup: get_text() returns empty string from bs4 Tag

Extract Information from BeautifulSoup bs4.element.Tag using Python

Can't seem to extract text from element using BS4

I need to extract an element from a tag using BeautifulSoup4

Extract text from within div tag using BeautifulSoup 4 in Python

BeautifulSoup4 can't extract only text from a tag

BeautifulSoup: extract text from anchor tag

BeautifulSoup: extract text from anchor tag

Match text from beautifulsoup children in Python bs4

extract title tag element with beautifulsoup4

python bs4 extract from attribute inside button class

Get the text from a div tag in html with bs4 python

How to extract text from 'a' element with BeautifulSoup?

Extracting text from BeautifulSoup tag element

Trim text from scraped element - Python / bs4

beautifulsoup how to extract text from a specific class

BeautifulSoup: How do I extract the text child element with no tag?

How to extract only the text inside a given class or tag using BeautifulSoup?

How to get inner text value of an HTML tag with BeautifulSoup bs4?

find a tag by beautifulsoup and extract element

bs4 Tag element returning 'NoneType' when trying to extract information

bs4 How can I extract the text within <p> tag

BeautifulSoup: Extract the text that is not in a given tag

Multiprocessing BeautifulSoup bs4.element.Tag

Extract text only except the content of script tag from html with BeautifulSoup

How to extract text and tag attributes from xml using BeautifulSoup

How can I extract the text from the <em> tag using BeautifulSoup