Python IMDbPY – Getting movie ID from searched movies

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.

filter_none

edit
close

play_arrow

link
brightness_4
code

# 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 )

chevron_right


Output :

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

Another example :

filter_none

edit
close

play_arrow

link
brightness_4
code

# 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 )

chevron_right


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



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

1


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.