📅  最后修改于: 2023-12-03 14:45:59.076000             🧑  作者: Mango
Python IMDbPY是一个用于获取互联网电影数据库(IMDb)信息的Python包。使用Python IMDbPY,您可以轻松地从IMDb中获取电影,电视节目,演员,导演等信息。
您可以使用以下命令在命令行中安装Python IMDbPY:
pip install imdbpy
要使用Python IMDbPY,您需要首先从数据库中提取电影和其他信息。以下是提取Top 10电影的示例:
import imdb
ia = imdb.IMDb()
top_movies = ia.get_top250_movies()
for movie in top_movies[:10]:
print(movie['title'])
输出:
The Shawshank Redemption
The Godfather
The Godfather: Part II
The Dark Knight
12 Angry Men
Schindler's List
The Lord of the Rings: The Return of the King
Pulp Fiction
The Lord of the Rings: The Fellowship of the Ring
The Good, the Bad and the Ugly
以上代码使用Python IMDbPY获取Top 10电影的标题,并将它们打印在命令行中。
您还可以获取电影的其他信息,例如电影的演员,导演和流派。以下是一个查找电影信息的示例:
import imdb
ia = imdb.IMDb()
movie = ia.get_movie('0111161')
print(movie['title'])
print(movie['genres'])
print([actor['name'] for actor in movie['cast'][:3]])
print([director['name'] for director in movie['directors']])
输出:
The Shawshank Redemption
['Drama']
['Tim Robbins', 'Morgan Freeman', 'Bob Gunton']
['Frank Darabont']
以上代码使用Python IMDbPY获取电影“ The Shawshank Redemption”的标题,流派,前三名演员和导演。
Python IMDbPY是一个强大的Python包,可用于提取IMDb中有关电影和其他媒体的信息。它易于使用且具有广泛的功能,帮助开发人员将命令行工具或Web应用程序与IMDb集成。