Web Scraping IMDB movie rating using Python Last Updated : 23 Jul, 2025 Suggest changes Share Like Article Like Report We can scrape the IMDb movie ratings and their details with the help of the BeautifulSoup library of Python. Modules Needed:Below is the list of modules required to scrape from IMDB.requests: Requests library is an integral part of Python for making HTTP requests to a specified URL. Whether it be REST APIs or Web Scraping, requests must be learned for proceeding further with these technologies. When one makes a request to a URI, it returns a response.html5lib: A pure-python library for parsing HTML. It is designed to conform to the WHATWG HTML specification, as is implemented by all major web browsers.bs4: BeautifulSoup object is provided by Beautiful Soup which is a web scraping framework for Python. Web scraping is the process of extracting data from the website using automated tools to make the process faster.pandas: Pandas is a library made over the NumPy library which provides various data structures and operators to manipulate the numerical data.Approach:Steps to implement web scraping in python to extract IMDb movie ratings and its ratings:Import the required modules. Python from bs4 import BeautifulSoup import requests import re import pandas as pd Access the HTML content from the webpage by assigning the URL and creating a soap object. Python # Downloading imdb top 250 movie's data url = 'https://www.imdb.com/chart/top/' response = requests.get(url) soup = BeautifulSoup(response.text, "html.parser") Extract the movie ratings and their details. Here, we are extracting data from the BeautifulSoup object using Html tags like href, title, etc. Python movies = soup.select('td.titleColumn') crew = [a.attrs.get('title') for a in soup.select('td.titleColumn a')] ratings = [b.attrs.get('data-value') for b in soup.select('td.posterColumn span[name=ir]')] After extracting the movie details, create an empty list and store the details in a dictionary, and then add them to a list. Python # create a empty list for storing # movie information list = [] # Iterating over movies to extract # each movie's details for index in range(0, len(movies)): # Separating movie into: 'place', # 'title', 'year' movie_string = movies[index].get_text() movie = (' '.join(movie_string.split()).replace('.', '')) movie_title = movie[len(str(index))+1:-7] year = re.search('\((.*?)\)', movie_string).group(1) place = movie[:len(str(index))-(len(movie))] data = {"place": place, "movie_title": movie_title, "rating": ratings[index], "year": year, "star_cast": crew[index], } list.append(data) Now or list is filled with top IMBD movies along with their details. Then display the list of movie details Python for movie in list: print(movie['place'], '-', movie['movie_title'], '('+movie['year'] + ') -', 'Starring:', movie['star_cast'], movie['rating']) By using the following lines of code the same data can be saved into a .csv file be further used as a dataset. Python #saving the list as dataframe #then converting into .csv file df = pd.DataFrame(list) df.to_csv('imdb_top_250_movies.csv',index=False) Implementation: Complete Code Python from bs4 import BeautifulSoup import requests import re import pandas as pd # Downloading imdb top 250 movie's data url = 'https://www.imdb.com/chart/top/' response = requests.get(url) soup = BeautifulSoup(response.text, "html.parser") movies = soup.select('td.titleColumn') crew = [a.attrs.get('title') for a in soup.select('td.titleColumn a')] ratings = [b.attrs.get('data-value') for b in soup.select('td.posterColumn span[name=ir]')] # create a empty list for storing # movie information list = [] # Iterating over movies to extract # each movie's details for index in range(0, len(movies)): # Separating movie into: 'place', # 'title', 'year' movie_string = movies[index].get_text() movie = (' '.join(movie_string.split()).replace('.', '')) movie_title = movie[len(str(index))+1:-7] year = re.search('\((.*?)\)', movie_string).group(1) place = movie[:len(str(index))-(len(movie))] data = {"place": place, "movie_title": movie_title, "rating": ratings[index], "year": year, "star_cast": crew[index], } list.append(data) # printing movie details with its rating. for movie in list: print(movie['place'], '-', movie['movie_title'], '('+movie['year'] + ') -', 'Starring:', movie['star_cast'], movie['rating']) ##.......## df = pd.DataFrame(list) df.to_csv('imdb_top_250_movies.csv',index=False) Output: Along with this in the terminal, a .csv file with a given name is saved in the same file and the data in the .csv file will be as shown in the following image. P Priyank181 Follow Article Tags : Python Python-requests Web-scraping Python BeautifulSoup Python web-scraping-exercises Python bs4-Exercises +2 More Explore Python FundamentalsPython Introduction 2 min read Input and Output in Python 4 min read Python Variables 5 min read Python Operators 4 min read Python Keywords 2 min read Python Data Types 7 min read Conditional Statements in Python 3 min read Loops in Python - For, While and Nested Loops 5 min read Python Functions 5 min read Recursion in Python 4 min read Python Lambda Functions 5 min read Python Data StructuresPython String 5 min read Python Lists 4 min read Python Tuples 4 min read Python Dictionary 3 min read Python Sets 6 min read Python Arrays 7 min read List Comprehension in Python 4 min read Advanced PythonPython OOP Concepts 11 min read Python Exception Handling 5 min read File Handling in Python 4 min read Python Database Tutorial 4 min read Python MongoDB Tutorial 2 min read Python MySQL 9 min read Python Packages 10 min read Python Modules 7 min read Python DSA Libraries 15 min read List of Python GUI Library and Packages 3 min read Data Science with PythonNumPy Tutorial - Python Library 3 min read Pandas Tutorial 6 min read Matplotlib Tutorial 5 min read Python Seaborn Tutorial 15+ min read StatsModel Library- Tutorial 4 min read Learning Model Building in Scikit-learn 8 min read TensorFlow Tutorial 2 min read PyTorch Tutorial 6 min read Web Development with PythonFlask Tutorial 8 min read Django Tutorial | Learn Django Framework 7 min read Django ORM - Inserting, Updating & Deleting Data 4 min read Templating With Jinja2 in Flask 6 min read Django Templates 7 min read Python | Build a REST API using Flask 3 min read How to Create a basic API using Django Rest Framework ? 4 min read Python PracticePython Quiz 3 min read Python Coding Practice 1 min read Python Interview Questions and Answers 15+ min read My Profile ${profileImgHtml} My Profile Edit Profile My Courses Join Community Transactions Logout Like