Skip to content
Related Articles

Related Articles

Python IMDbPY – Getting movie ID from searched movies
  • Last Updated : 22 Apr, 2020

In this article we will see how we can get the movie id from searched movies, movie id is basically unique id given to each movie as movie name can be same but id will be distinct. We use search_movie method to search movies with the same name.

In order to get movie id we use movieID method.

Syntax : movies[0].movieID

Here movies is the list of movies returned by search_movie and movies[0] refer to first element in list

Argument : It takes no argument.



Return : It return string which is Movie ID

Below is the implementation.




# importing the module
import imdb
   
# creating instance of IMDb
ia = imdb.IMDb()
   
# name 
name = "Udta punjab"
   
# searching the name 
search = ia.search_movie(name)
  
  
# loop for printing the name and id
for i in range(len(search)):
      
    # getting the id
    id = search[i].movieID
      
    # printing it
    print(search[i]['title'] + " : " + id )

Output :

Udta Punjab : 4434004
Diljit Dosanjh (Udta Punjab) : 6574338

Another example :




# importing the module
import imdb
   
# creating instance of IMDb
ia = imdb.IMDb()
   
# name 
name = "3 idiots"
   
# searching the name 
search = ia.search_movie(name)
  
  
# loop for printing the name and id
for i in range(len(search)):
      
    # getting the id
    id = search[i].movieID
      
    # printing it
    print(search[i]['title'] + " : " + id )

Output :

3 Idiots : 1187043
3 idiotas : 3685624
3 Idiots : 12049418
3 Idiots w/ GUNS : 0222441
3 Idiots on Wheels : 6689378
3 Idiots Try Candy! : 8474256
3 Idiots; How Cho Copes with Slump : 9419952
The Idiots : 0154421
Idiots : 0341476
Vidiots : 5830890
Idiotest : 3607166
Idiotsitter : 3532050
The Idiot : 0043614
Idioten : 7147976
Idiots : 1687235
4 Idiots : 6470848
Idiots : 2622956
The Idiot : 0051762
Idiots : 6866900
Idiot : 0366028

 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

My Personal Notes arrow_drop_up
Recommended Articles
Page :