gpt4 book ai didi

python - 获取导演执导的电影列表 - IMDbPY

转载 作者:太空宇宙 更新时间:2023-11-03 17:46:56 24 4
gpt4 key购买 nike

我使用下面的代码来获取特定电影的导演姓名。如何获得该导演执导的所有电影的列表?在这种情况下,我选择了《星际穿越》,而我的导演将是克里斯托弗·诺兰。那么如何列出他导演的所有电影呢?

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

最佳答案

您可以使用以导演 ID 作为参数的方法 get_person,并通过使用键 director movie 访问 person 对象来查找他导演的电影的名称:

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

关于python - 获取导演执导的电影列表 - IMDbPY,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29642595/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com