Hi I'm trying to get some information from a website. Pardon me if I formatted anything wrong this is my first time posting to SO.
soup.find('div', {"class":"stars"})
From this I receive
<div class="stars" title="4.0 star rating">
<i class="star star--large star-0"></i><i class="star star--large star-
1"></i><i class="star star--large star-2"></i><i class="star star--large
star-3"></i><i class="star star--large star-4 star--large--muted"></i>
</div>
I need that "4.0 star rating"
When I use:
soup.find('div', {"class":"stars"})["title"]
It works, but not for find_all. But I'm trying to find all cases and put them into a list.
This is my full code below.
def get_info():
from IPython.display import HTML
import requests
from bs4 import BeautifulSoup
n = 1
for page in range(53):
url = f"https://www.sitejabber.com/reviews/apple.com?page=
{n}&sort=Reviews.processed&direction=DESC#reviews"
r = requests.get(url)
soup = BeautifulSoup(r.text, 'lxml')
all_reviews = soup.find_all('div', {'class':"truncate_review"})
all_dates = soup.find_all('div', {'class':'review__date'},'title')
all_titles = soup.find_all('span', {'class':'review__title__text'})
reviews_class = soup.find('div', {"class":"review__stars"})
for review in all_reviews:
all_reviews_list.append(review.text.replace("\n","").replace("\t",""))
for date in all_dates:
all_dates_list.append(date.text.replace("\n","").replace("\t",""))
for title in all_titles:
all_titles_list.append(title.text.replace("\n","").replace("\t",""))
for stars in reviews_class.find_all('div', {'class':'stars'}):
all_star_ratings.append(stars['title'])
n += 1
Sorry my indenting got a bit messed up but that is my full code.