There are multiple ways to get the desired price values.
You can use a CSS selector and get the first child of every div
having product-price
class:
for price in soup.select("div.product-price > div:nth-of-type(1)"):
print price.get_text(strip=True)
This would print:
Rs 33490Rs 42990(22%)
Rs 26799Rs 31500(15%)
...
Rs 41790Rs 44990(7%)
Rs 48000Rs 50000(4%)
nth-of-type
documentation reference.
Note that along with an actual price it contains the previous price which is on the strikethrough font. To get rid of it, get only top level text from the div
by using find()
with text=True
and recursive=False
:
for price in soup.select("div.product-price > div:nth-of-type(1)"):
print price.find(text=True, recursive=False).strip()
Prints:
Rs 33490
Rs 26799
...
Rs 41790
Rs 48000
You can go further and omit the Rs
at the beginning and get the int (or float) price values:
for div in soup.select("div.product-price > div:nth-of-type(1)"):
price = div.find(text=True, recursive=False).strip()
price = float(price.replace("Rs ", ""))
print price
Prints:
33490.0
26799.0
...
41790.0
48000.0