Hi all.
I’m trying to web scarp iherb but I’m having trouble extrating the data of the ratings (aka the number of stars of each product). Here’s my work:
import requests
from bs4 import BeautifulSoup as soup
url = ‘Whey Protein • Whey Protein Isolate and Concentrate | iHerb’
html = requests.get(url=url,headers=header_1)
html.status_code
bsobj = soup(html.content, ‘lxml’)
whey = bsobj.findAll(‘div’,{‘class’:‘product-inner product-inner-wide’})
for item in whey:
dict_1 = {
“title” : item.find(‘div’,{“class”:“product-title”}).text,
“link” : item.find(‘a’,{“class”:“absolute-link product-link”})[‘href’],
“reviews” : int(item.find(‘a’,{“class”:“rating-count”}).text),
“stars” : item.find(‘a’,{“class”:“stars”}).text
}
so the problem is I can’t get the number of stars out of 5 of each product. What should I do? Many thanks.