Issue
try:
price = soup.find("span", attrs={'class':'PriceBoxPlanOption__offer-price___3v9x8 PriceBoxPlanOption__offer-price-cp___2QPU_'}).string.strip().replace(',', '').replace('₹','')
# we are omitting unnecessary spaces
# and commas form our string
except AttributeError:
price = "NA"
print("Products price = ", price)
Product Link: https://www.1mg.com/otc/iodex-ultra-gel-otc716295 the below class is not returning any value, but it should
class = PriceBoxPlanOption__offer-price___3v9x8 PriceBoxPlanOption__offer-price-cp___2QPU_
Solution
The following code will get you the result you want:
import requests
from bs4 import BeautifulSoup
headers= {'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36'}
r = requests.get('https://www.1mg.com/otc/iodex-ultra-gel-otc716295', headers=headers)
soup = BeautifulSoup(r.text, 'html.parser')
elem = soup.select_one('.PriceBoxPlanOption__offer-price___3v9x8.PriceBoxPlanOption__offer-price-cp___2QPU_')
print(elem.text)
Result:
₹171
Docs for BeautifulSoup can be found at https://www.crummy.com/software/BeautifulSoup/bs4/doc/#the-value-true
Answered By - Barry the Platipus
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.