'How do I scrape this Flex element on a website using BeautifulSoup?

I am trying to scrape this product page on Home Depot for its price. However, I noticed that the div class I'm trying to scrape from has a 'flex' element next to it. Could someone explain how I can scrape this? Does beautifulsoup and lxml still work in this case?

from bs4 import BeautifulSoup
import requests


ua = {"User-Agent":"Mozilla/5.0"}
url = ('https://www.homedepot.com/p/POWERTEC-12-in-80-Grit-PSA-Aluminum-Oxide-Sanding-Disc-Self-Stick-3-Pack-110603/300060135')
page = requests.get(url, headers=ua)
soup = BeautifulSoup(page.text, "lxml")

price = soup.find('div', class_="price-format__main-price")
print(price)


Solution 1:[1]

I'm not sure I understand your problem, are you trying to get the price without the cents because there is no decimal place?

You could do something like this to only get info from the first few span tags and not the last one:

price = soup.find('div', class_="price-format__main-price")
price_value = ''.join([x.text for x in price.find_all('span')[:-1]])
print(price_value)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 bushcat69