Python IMDbPY - 从搜索的电影中获取电影 ID
在本文中,我们将了解如何从搜索到的电影中获取电影 ID,电影 ID 基本上是赋予每部电影的唯一 ID,因为电影名称可以相同但 ID 不同。我们使用search_movie
方法来搜索同名电影。
为了获取电影ID,我们使用movieID
方法。
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
下面是实现。
# 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 )
输出 :
Udta Punjab : 4434004
Diljit Dosanjh (Udta Punjab) : 6574338
另一个例子 :
# 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 )
输出 :
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