Issue
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")
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
Answered By - Andrej Kesely
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.