擅长:python、mysql、java
<P>您必须考虑^ {CD1>}将返回一个HOLL对象的列表,而不是一个带有“名称”键的字典。<p>
<p>我注意到的另一件(次要)事情是,您获取第一个结果的电影ID,然后再次获取电影。这可以使用<code>ia.update</code>方法省略</p>
<p>一个有效的例子(仍然假设了很多事情,比如搜索至少会给出一个结果):</p>
<pre><code>#!/usr/bin/env python3
import sys
from imdb import IMDb
ia = IMDb()
def getmovieID(movie_name):
movie = ia.search_movie(movie_name)[0] # a Movie instance.
ia.update(movie)
return movie
def getcast(movie_name):
movie = getmovieID(movie_name)
casts = []
for person in movie.get('cast', []):
casts.append(person['name'])
return casts
print(getcast('The Dark Knight'))
</code></pre>