如何查找演员表演的电影列表?

How to Find list of movies acted by an actor?

我使用以下代码获取特定电影的演员阵容(例如前 2 名)。我怎样才能得到 actor/actress 出演的所有电影的列表? 例如,我选择电影 Inception (1375666),演员是 Leonardo DiCaprio。那么我怎样才能得到莱昂纳多·迪卡普里奥出演的所有电影的列表呢??

from imdb import IMDb
ia = IMDb()

movie = ia.get_movie('1375666')
actor = movie['cast']
print "Cast: "
for i in actor[:2]:
    for j in ia.search_person(str(i))[:1]:
        print i, j.personID

这很简单。让我们从你的例子中取 actor 并得到他的完整电影:

>>> full_person = ia.get_person(actor[0].getID(), info=["filmography"])
>>> full_person.keys()
['name', u'producer', u'archive footage', u'self', u'writer', u'actor', u'soundtrack', 'in development', 'birth notes', u'thanks', 'akas', 'birth date', 'canonical name', 'long imdb name', 'long imdb canonical name']
>>> full_person["actor"]
[<Movie id:1663202[http] title: ...]

最后一行为您提供此人是演员的电影列表。但请记住,在 ia.get_person(...) 中,您向 imdb.com 发出了一个 http 请求。对于演员名单,这可能需要一些时间。