<jupyter_start><jupyter_text>Set-up<jupyter_code># load packages
import requests
from bs4 import BeautifulSoup
# Define the URL of the site
base_site = "https://editorial.rottentomatoes.com/guide/140-essential-action-movies-to-watch-now/2/"
# sending a request to the webpage
response = requests.get(base_site)
response
# get the HTML from the webpage
html = response.content
# convert the HTML to a BeatifulSoup object
soup = BeautifulSoup(html, 'lxml')
# Find the encompassing div tags
divs = soup.find_all("div", {"class": "col-sm-18 col-full-xs countdown-item-content"})
divs<jupyter_output><empty_output><jupyter_text>Extracting the rest of the information  Adjusted score<jupyter_code># The adjusted scores can be found in a div with class 'info countdown-adjusted-score'
adj_scores = [div.find("div", {"class": "info countdown-adjusted-score"}) for div in divs]
adj_scores
# Inspecting an element
adj_scores[0]
# By inspection we see that the string we are looking for is the second child of the 'div' tag
adj_scores[0].contents[1]  # Note the extra whitespace at the end
# Extracting the string (without '%' sign and extra space)
adj_scores_clean = [score.contents[1].strip('% ') for score in adj_scores]
adj_scores_clean
# Converting the strings to numbers
final_adj = [float(score) for score in adj_scores_clean] # Note that this time the scores are float, not int!
final_adj<jupyter_output><empty_output><jupyter_text>Synopsis<jupyter_code># The synopsis is located inside a 'div' tag with the class 'info synopsis'
synopsis = [div.find('div', class_='synopsis') for div in divs]
synopsis
# Inspecting the element
synopsis[0]
# The text is the second child
synopsis[0].contents[1]
# Extracting the text
synopsis_text = [syn.contents[1] for syn in synopsis]
synopsis_text<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09828823854224185, 'fraction_numerical': 0.008282716731087797, 'mean_word_length': 5.996138996138996, 'pattern_counts': {'":': 2, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 1}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '382048', 'license': 'MIT', 'n_tokens_mistral': 606, 'n_tokens_neox': 579, 'n_words': 196, 'path': 'Section 6/S6_L50/Section 6 -Extracting the rest of the information - Exercise - Solution.ipynb', 'repo_name': 'guilhermeaugusto9/Web-Scraping-and-API-Fundamentals-in-Python', 'size': '1811'}