Home > Net >  How to extracted specific information such as cost and name of a product?
How to extracted specific information such as cost and name of a product?

Time:11-09

But I facing problem to extract data from bs4 tag and i am not able to extract only the product name and costi am not able to extract exact exact 159995(without rupee sign and commas)

same goes with the name of the product not able to extract name of the productenter image description here

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)))
  • Related