📜  Python IMDbPY – 搜索一个人(1)

📅  最后修改于: 2023-12-03 15:04:05.496000             🧑  作者: Mango

Python IMDbPY – 搜索一个人

Python IMDbPY是一个强大的Python库,可用于搜索Internet Movie Database (IMDb)上的电影、电视节目、演员等。它允许开发人员使用Python来获取IMDb的信息,包括电影、电视节目、演员的详细信息。

安装

要安装Python IMDbPY,可以使用pip包管理器。打开命令行窗口并输入以下命令:

pip install IMDbPY
搜索一个人

要搜索电影、电视节目、演员等,需要使用IMDbPY库中的IMDb类。接下来,我们将看一下如何使用IMDbPY库搜索IMDb上的一个人。

步骤1:导入Imdb类

要使用IMDb类,需要从IMDbPY库中导入它。将以下代码添加到Python脚本的开头:

from imdb import IMDb
步骤2:创建一个Imdb对象

IMDb对象是访问IMDb数据库的入口。使用以下代码创建一个IMDb对象:

ia = IMDb()
步骤3:搜索人

使用IMDbPY库搜索人非常简单。通过在IMDb对象上调用search_person方法来搜索人。例如,要搜索名为Tom Hanks的人:

people = ia.search_person('Tom Hanks')
步骤4:查看搜索结果

进行人物搜索后,将返回一个Person对象列表。要查看第一个搜索结果的信息,可以使用以下代码:

person = people[0]
ia.update(person)

print(person.summary())

summary方法将返回一个字符串,包含人的基本信息,例如出生日期、职业和特定影片的重要信息。

输出

以下是搜索Tom Hanks并运行上述代码后的示例输出:

Thomas Jeffrey Hanks was born in Concord, California, to Janet Marylyn (Frager), a hospital worker, and Amos Mefford Hanks, an itinerant cook. His mother's family, originally surnamed Fraga, was entirely Portuguese, while his father was of mostly English ancestry. Tom grew up in what he has called a "fractured" family. He moved around a great deal after his parents' divorce, living with a succession of step-families. No problems, no alcoholism - just a confused childhood. He has no acting experience in college and, in fact, credits the fact that he couldn't get cast in a college play with actually starting his career - he went downtown, auditioned for a community theater play, was invited by the director of that play to go to Cleveland, and there his acting career gradually began. His big break was being cast in the TV series Bosom Buddies (1980). ...

这是搜索结果的概述,它列出了Tom Hanks的基本信息以及各种以前他在其中扮演的角色。

结论

Python IMDbPY是一个功能强大的Python库,可用于访问IMDb数据库并获取电影、电视节目、演员等的信息。在本指南中,我们了解了如何使用它来搜索人。现在你已经学会了如何使用Python IMDbPY搜索IMDb上的人物,可以使用它来获取关于某一人的相关信息。