Extract previous price from Amazon Page

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.


Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x