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.
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...
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 [ ]:](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F42be835d-db2f-4cd3-84d8-9eb2014efa10%2F75b13eb9-7fe9-4825-9dea-67be68581083%2F2s2uen_processed.png&w=3840&q=75)
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

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 2 steps with 1 images

Recommended textbooks for you

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 Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science

Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning

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 Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science

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
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning

Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education

Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY