Les séries empirent-elles avec le temps?
Demande
Belle soupe
Pandas
Seaborn
# obtain the html code as a string
response = requests.get(url_serie + url_season)
html = response.text
# create a BeautifulSoup object
soup = bs4.BeautifulSoup(html, “html.parser”)
rates_season = {}
# we obtain all division tags with the class attribute “ipl-rating-star small”
division_tags = soup.find_all(class_=”ipl-rating-star small”)# we loop through the tags and extract the scores
# we create a dictionary with the scores
for index, tag in enumerate(division_tags):
rate = tag.find(class_=”ipl-rating-star__rating”).text
episode = ‘Episode_’ + str(index + 1)
# we insert the score in the dictionary
rates_season[episode] = float(rate)
# we append the dictionary to a list
rates_all.append(rates_season)
# get next season anchor tag
next_season = soup.find(“a”, id=”load_next_episodes”)
# if next_season equal to None break the loop
if not next_season:
break
# if next_season is not equal to None, we access the url
url_season = next_season.get(‘href’)
df = pd.DataFrame(rates_all, index=list(map(lambda x: ‘Season_’ + str(x+1), range(num_season))))