Please don't copy tag (a link) that is itself inside of aDIV with class lister-item-content . That is, for each film in the list films, find the div with the class lister-item-content and then find...


Please don't copy


PS5: Webscraping<br>Suggested Solutions<br>Import BeautifulSoup, json, requesrts, and pandas.<br>In [ ]: from bs4 import BeautifulSoup<br>import pandas as pd<br>import requests<br>import re<br>import json<br>IMDB top 50 rated films.<br>The following URL, https://www.imdb.com/search/title/?groups=top_250&sort=user_rating, is a link to the top 50 rated films on IMDB. Create a pandas<br>DataFrame with three columns: Title, Year, and Rating, pulling the data from the webpage.<br>We can do this in steps. First, get the HTML code that generated the webpage.<br>In [ ]:<br>Using the
tag (a link) that is itself inside of a DIV with class lister-item-content . That is, for each film in the list films, find the div with the class lister-item-content and then find the first link and get the text of that link. Store this in a dataframe called films_df (which currently has a single column, 'Title'). In [ ]: Repeat: now create a list of the year of each film, and store it in a second column of films_df. This is even easier since each year is stored in a span with class lister-item-year. Convert the text to an integer (which means first formating the string to remove the parenthesis). In []: Repeat: now create a list of the score of each film. This time, you have to figure out where it is stored. Convert the text to an float and store it in the 3rd column of the df. In [ ]: "/>
Extracted text: PS5: Webscraping Suggested Solutions Import BeautifulSoup, json, requesrts, and pandas. In [ ]: from bs4 import BeautifulSoup import pandas as pd import requests import re import json IMDB top 50 rated films. The following URL, https://www.imdb.com/search/title/?groups=top_250&sort=user_rating, is a link to the top 50 rated films on IMDB. Create a pandas DataFrame with three columns: Title, Year, and Rating, pulling the data from the webpage. We can do this in steps. First, get the HTML code that generated the webpage. In [ ]: Using the "Inspect Element" tool in a browser, see that each film is displayed in a DIV with the class lister-item. Use BS to find all such elements and store them in a list called films. Then, create a list of the title of each film. Notice, by inspecting the HTML, that the title is contained inside of a

tag (a link) that is itself inside of a DIV with class lister-item-content . That is, for each film in the list films, find the div with the class lister-item-content and then find the first link and get the text of that link. Store this in a dataframe called films_df (which currently has a single column, 'Title'). In [ ]: Repeat: now create a list of the year of each film, and store it in a second column of films_df. This is even easier since each year is stored in a span with class lister-item-year. Convert the text to an integer (which means first formating the string to remove the parenthesis). In []: Repeat: now create a list of the score of each film. This time, you have to figure out where it is stored. Convert the text to an float and store it in the 3rd column of the df. In [ ]:
Jun 09, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here