I am using Beautiful Soup to scrape a website, and am having trouble using decompose() to remove a <del> tag inside the section I'm scraping.
All products on the page have a price inside a <div> with the class product-card__price. However, some products are discounted and contain two prices in this <div>. The full price is contained in a tag (<del>$</del>) which precedes the current price.
# Example 1 - one price
<div class="flex-split__item product-card__price">
$11.99
</div>
# Example 2 - two prices
<div class="flex-split__item product-card__price">
<del>$9.99</del>
$8.99
</div>
If I simply grab the text in this div with price = container.find(class_ = 'product-card__price').text.strip(), Example #2 will return $9.99 $8.99. Reading the documentation, I thought that I should be able to use decompose() to strip out the text contained in <del></del> with the following code:
if container.find(class_ = 'product-card__price'):
if container.find('del'):
full_price = container.find('del').text.strip()
current_price = container.find(class_ = 'product-card__price').decompose()
else:
full_price = None
price = container.find(class_ = 'product-card__price').text.strip()
else:
price = None
full_price = None
However, this returns the result None. I'm able to split the string with Regexp, but would like to understand what I am doing wrong with decompose/extract. Example webpage is here.