获取导演导演的电影列表 - IMDbPY
Get list of movies directed by director- IMDbPY
我使用以下代码获取特定电影的导演姓名。我怎样才能得到导演执导的所有电影的列表。
在这种情况下,我选择了《星际穿越》,我得到的导演将是克里斯托弗诺兰。那么如何列出他导演的所有电影呢?
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
您可以使用方法 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
我们在 2022 年,我尝试了您的代码@halex,但它不再起作用了。这就是我找到新方法的原因:
def get_director_id(mv_id):
ia = imdb.IMDb()
movie= ia.get_movie(mv_id)
dict_directors={}
directors= movie['director']
for dir in directors:
dict_directors[dir]= dir.personID
return(dict_directors)
def get_director_movie(nb, dir_id):
ia = imdb.IMDb()
dict_mv={}
dir_info= ia.get_person_filmography(dir_id)
tmp= dir_info['data']['filmography']['director']
for i in range(len(tmp)-1, len(tmp)-nb-1, -1):
title= str(dir_info['data']['filmography']['director'][i])
print(title)
id= dir_info['data']['filmography']['director'][i].movieID
print(id)
dict_mv[title]= id
return(dict_mv)
dict= get_director_movie(3, "0905154")
titles= list(dict.keys())
id= list(dict.values())
我使用以下代码获取特定电影的导演姓名。我怎样才能得到导演执导的所有电影的列表。 在这种情况下,我选择了《星际穿越》,我得到的导演将是克里斯托弗诺兰。那么如何列出他导演的所有电影呢?
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
您可以使用方法 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
我们在 2022 年,我尝试了您的代码@halex,但它不再起作用了。这就是我找到新方法的原因:
def get_director_id(mv_id):
ia = imdb.IMDb()
movie= ia.get_movie(mv_id)
dict_directors={}
directors= movie['director']
for dir in directors:
dict_directors[dir]= dir.personID
return(dict_directors)
def get_director_movie(nb, dir_id):
ia = imdb.IMDb()
dict_mv={}
dir_info= ia.get_person_filmography(dir_id)
tmp= dir_info['data']['filmography']['director']
for i in range(len(tmp)-1, len(tmp)-nb-1, -1):
title= str(dir_info['data']['filmography']['director'][i])
print(title)
id= dir_info['data']['filmography']['director'][i].movieID
print(id)
dict_mv[title]= id
return(dict_mv)
dict= get_director_movie(3, "0905154")
titles= list(dict.keys())
id= list(dict.values())