Python IMDbPY - 从搜索的电影中获取标题
在本文中,我们将了解如何从搜索的电影列表中获取电影的标题。我们使用 search_movie 方法来查找所有相关的电影。 search_movie 方法返回列表,列表的每个元素都作为字典工作,即可以通过给出数据的键来查询它们,这里的键是标题。
Syntax : movies[0][‘title’]
Here movies is the list return by search_movie method and movies[0] refer to the first element of list.
Return : It returns string i.e title.
下面是实现:
Python3
# importing the module
import imdb
# creating instance of IMDb
ia = imdb.IMDb()
# name of the movie
name = "Jab Taare Utare Zameen Par"
# searching the name of the movie
search = ia.search_movie(name)
# printing whole list
print(search)
# printing the movies
for i in range(len(search)):
print(search[i]['title'])
Python3
# importing the module
import imdb
# creating instance of IMDb
ia = imdb.IMDb()
# name of the movie
name = "Udta punjab"
# searching the name of the movie
search = ia.search_movie(name)
# printing the movies
for i in range(len(search)):
print(search[i]['title'])
输出 :
[Movie id:8142208[http] title:_Jab Taare Utare Zameen Par (2017)_]
Jab Taare Utare Zameen Par
另一个例子
Python3
# importing the module
import imdb
# creating instance of IMDb
ia = imdb.IMDb()
# name of the movie
name = "Udta punjab"
# searching the name of the movie
search = ia.search_movie(name)
# printing the movies
for i in range(len(search)):
print(search[i]['title'])
输出 :
Udta Punjab
Diljit Dosanjh (Udta Punjab)