How to find main price and discounted price in a webpage using selenium and python?

I am trying to find a way to find main price and also discounted price in a webpage but I can get just one of them and I need a good pattern or method to extract all price and discounted prices from all kind of pages (A general regular expression or something). Example:

My code:

    html = driver.page_source
    soup = BeautifulSoup(html, "html.parser")

                    for price in soup.findAll('span', {'class': [re.compile("price"), re.compile("cost")]}):
                        price = convert_numbers.persian_to_english(price.text)  # 512396044
                        #print(re.sub(r'\D', '', price))
                        print(re.sub(r'\D', '', price))
                        for result in price:
                            #get the main price ?
                            price = result.find('span')[0]
                            #get the discounted price ?
                            discounted_price = result.find('span')[1]

The result is a price in similar product (from product suggestion segment), and it's not correct price from current product and also is without discounted price.


  • Try:

    import requests
    from bs4 import BeautifulSoup
    url = ""
    soup = BeautifulSoup(requests.get(url).content, "html.parser")
    current_price = soup.select_one(".price ins").text.split()[0]
    before_price = soup.select_one(".price del").text.split()[0]
    print(f"{current_price=} {before_price=}")


    current_price='21,700,000' before_price='22,700,000'