Python IMDbPY – Getting title from searched movie
In this article we will see how we can get the title of movie from the searched list of movies. We use search_movie method to find all the related movies. search_movie method returns list and each element of list work as a dictionary i.e. they can be queried by giving the key of the data, here key will be title.
Syntax : movies[0][‘title’]
Here movies is the list return by search_movie method and movies[0] refer to the first element of list.
Return : It returns string i.e title.
Below is the implementation:
# importing the moduleimport imdb # creating instance of IMDbia = imdb.IMDb() # name of the moviename = "Jab Taare Utare Zameen Par" # searching the name of the moviesearch = ia.search_movie(name) # prinitng whole listprint(search) # printing the moviesfor i in range(len(search)): print(search[i]['title']) |
Output :
[Movie id:8142208[http] title:_Jab Taare Utare Zameen Par (2017)_] Jab Taare Utare Zameen Par
Another example
# importing the moduleimport imdb # creating instance of IMDbia = imdb.IMDb() # name of the moviename = "Udta punjab" # searching the name of the moviesearch = ia.search_movie(name) # printing the moviesfor i in range(len(search)): print(search[i]['title']) |
Output :
Udta Punjab Diljit Dosanjh (Udta Punjab)
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course


