Python IMDbPY – Getting company ID from searched companies

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

In order to get company id we use companyID method.

Syntax : companies[0].companyID

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

Argument : It takes no argument.



Return : It return string which is company 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 = "Marvel"
   
# searching the name 
search = ia.search_company(name)
  
  
# loop for printing the name and id
for i in range(len(search)):
      
    # getting the id
    id = search[i].companyID
      
    # printing it
    print(search[i]['name'] + " : " + id )

chevron_right


Output :

Marvel Studios : 0051941
Marvel Entertainment : 0047120
Marvel Family Entertainment : 0769644
Marvel Enterprises : 0095134
Marvel Productions : 0106768
Marvel Movies : 0028071
Marvelous Productions : 0644186
Marvelous : 0497759
Marvel Animation : 0249290
Marvel Comics : 0131570
Marvel Knights : 0255123
Marvel.com : 0672091
Marvel Television : 0377521
Marvelous films : 0567626
Carvell Productions : 0208235
Marvel Comics Group : 0390765
Carvel : 0039046
Marvelous Mascots : 0521917
Marvee : 0345899
Marvelous 1st Studio : 0700950

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 = "Pixel"
   
# searching the name 
search = ia.search_company(name)
  
  
# loop for printing the name and id
for i in range(len(search)):
      
    # getting the id
    id = search[i].companyID
      
    # printing it
    print(search[i]['name'] + " : " + id )

chevron_right


Output :

Pixel : 0022125
Pixel : 0758724
Pixel : 0445832
Pixel Magic : 0065379
Pixeldna : 0226585
Pixeleyed Pictures : 0787858
Pixelette Studios : 0335815
Pixel Brothers : 0228269
Lani Pixels : 0393856
Dilated Pixels : 0296183
PixelDog : 0436099
Pixels : 0582635
Pixell : 0405667
Big Red Pixel : 0095582
Blue Pixel : 0694611
Pixel Plus : 0395349
Zapixel : 0387827
PixelFade : 0658011
Biopixel : 0600235
Pixelpro : 0452072
?

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.




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 :

Be the First to upvote.


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