PS5: Webscraping Suggested Solutions Import BeautifulSoup, json, requesrts, and pandas. [ ]: 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.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
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 <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 [ ]:
Transcribed Image 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 <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 [ ]:
Expert Solution
steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY