我使用以下代码获取特定电影的导演名称。如何获得导演指导的所有电影列表。 在这种情况下,我选择了Interstellar,我得到的导演将是Christopher Nolan。那么如何列出他指导的所有电影呢?
from imdb import IMDb
ia = IMDb()
movie = ia.get_movie('0816692')
print "Name of the movie: ", movie
for i in movie['director']:
print "Director: ", i
for k in ia.search_person(str(i))[:1]:
print k.personID
答案 0 :(得分:1)
您可以使用方法get_person
将导演的ID作为参数,并通过使用键director movie
访问人物对象来查找他所指导的电影的名称:
from imdb import IMDb
ia = IMDb()
movie = ia.get_movie('0816692')
print "Name of the movie: ", movie
for i in movie['director']:
print "Director: ", i
for k in ia.search_person(str(i))[:1]:
director = ia.get_person(k.personID)
print "Movies directed by %s" % director
print "-------------------------------"
for movie_name in director['director movie']:
print movie_name
<强>更新强>
我在库中玩了一点,发现了一个更简单的方法解决了你的问题而没有嵌套的for循环:
from imdb import IMDb
ia = IMDb()
movie = ia.get_movie('0816692')
print "Name of the movie: ", movie
for i in movie['director']:
print "Director: ", i
director = ia.search_person(i["name"])[0]
ia.update(director)
print "Movies directed by %s:" % director
for movie_name in director["director movie"]:
print movie_name