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?
To extract attributes of elements in Beautiful Soup, use the [~] notation. For instance, el["id"] retrieves the value of the id attribute.
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.
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.
Extract the string from the element:
volume = soup.findAll("span", {"id": "volume"})[0].string
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With