Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Grab specific element/value from a Div

The element structure I’m trying to grab sort of looks like this

<div class="main">
    <div class="cost-box">
        <ins><span>$</span><price>10.00</price></ins>
    </div>
</div>

Using the code below, I managed to grab the cost-box class, but I have no idea how to grab the 10.00 value under the price element.

import requests
from bs4 import BeautifulSoup as bs

url = 'https://www.energyavenue.com/Lotus-LED/LBL-KDB-1'

response = requests.get(url).text

soup = bs(response, 'html.parser')

container = soup.find('div', class_="cost-box")

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Try:

import requests
from bs4 import BeautifulSoup as bs

url = "https://www.energyavenue.com/Lotus-LED/LBL-KDB-1"

response = requests.get(url).text
soup = bs(response, "html.parser")

container = soup.find("div", class_="cost-box")
price = container.price    # <-- get <price> tag from container
print(price.text)

Prints:

34.25
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading