Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

beautiful soup just get the value inside the tag

Tags:

The following command:

volume = soup.findAll("span", {"id": "volume"})[0] 

gives:

<span class="gr_text1" id="volume">16,103.3</span> 

when I issue a print(volume).

How do I get just the number?

like image 448
user1357015 Avatar asked Feb 25 '14 02:02

user1357015


People also ask

How do you get value from BeautifulSoup?

To extract attributes of elements in Beautiful Soup, use the [~] notation. For instance, el["id"] retrieves the value of the id attribute.

What is a tag in BeautifulSoup?

Going down. One of the important pieces of element in any piece of HTML document are tags, which may contain other tags/strings (tag's children). Beautiful Soup provides different ways to navigate and iterate over's tag's children.

Which BeautifulSoup method will find all table tags on the page?

In order to print all the heading tags using BeautifulSoup, we use the find_all() method. The find_all method is one of the most common methods in BeautifulSoup.


1 Answers

Extract the string from the element:

volume = soup.findAll("span", {"id": "volume"})[0].string 
like image 70
isedev Avatar answered Sep 28 '22 04:09

isedev