Home > Back-end >  Extract previous price from Amazon Page
Extract previous price from Amazon Page

Time:10-23

I used BeautifulSoup in Python for extract the previous price on an Amazon page, but the code that i used prints the current price and not the previous price.

I tryed:

priceold = soup.find(class_="a-span12 a-color-secondary a-size-base").get_text()

The page is this https://www.amazon.it/dp/B08LQ3WPWS/ and i need to extract 799,99€ (the previous price).

The HTML code on the page is:

<tr><td class="a-color-secondary a-size-base a-text-right a-nowrap">Prezzo consigliato:</td><td class="a-span12 a-color-secondary a-size-base">
<span class="a-price a-text-price a-size-base" data-a-size="b" data-a-strike="true" data-a-color="secondary"><span class="a-offscreen">799,99€</span><span aria-hidden="true">799,99€</span></span>

I need only one 799,99€. How can i select it correctly with BeautifulSoup?

I think i need to select class a-span12 a-color-secondary a-size-base and at the same time class a-offscreen.

CodePudding user response:

This should work:-

#get price block
price_block=soup.find('span',class_='a-price a-text-price a-size-base')

#get previous price within price block
previous_price=price_block.find('span',class_='a-offscreen')
print(previous_price.text)
  • Related