But I facing problem to extract data from bs4 tag and i am not able to extract only the product name and cost
same goes with the name of the product not able to extract name of the product
I tried using indexing but that failed since it is a tag I have also used .getText()
and .get_text()
and tried converting into str and append into list
that also failed and not able to get exact info required.
I am not able to extract exact 159995(without rupee sign and commas) in first image and product name in second image
CodePudding user response:
Based on your example it should be the following, cause there is only one tag in your ResultSet
:
soup.select_one('.BNuCI').get_text(strip=True)
Else you have to iterate your ResultSet
:
for e in soup.select('.BNuCI'):
print(e.get_text(strip=True))
Based on your comment:
It is the same way for the cost and you could extract with regex
e.g. the numbers only:
import re
cost = ''.join(re.findall(r'\d ', soup.select_one('.YOURCLASSVALUES').get_text(strip=True)))