使用IMDbPY获取10,000个电影情节

问题描述 投票:0回答:1

我正在使用IMDbPY与公开的IMDb数据集(https://www.imdb.com/interfaces/)一起使用pandas创建自定义数据集。公共数据集包含很多很棒的信息,但据我所知,不包含情节信息。 IMDbPY确实包含绘图摘要,以及电影类/字典的情节,概要和关键字形式的情节的情节概要和关键字。

我可以通过进行API调用得到各个键的图:ia.get_movie(movie_index[2:])['plot'][0]我使用[2:],因为索引的前2个字符在公共数据集中是'tt'而且[0]因为有很多情节摘要所以我我是IMDbPY的第一个。

但是,要获得10,000个绘图摘要,我需要进行10,000次API调用,这需要7.5小时,假设每次API调用需要2.7秒(这是我使用tqdm找到的)。所以解决这个问题的方法是让它在一夜之间运行。还有其他解决方案吗?另外,有没有比我目前的方法更好的方法来创建一个字符,其中键作为电影索引(例如“Shawshank Redemption”的tt0111161)和值作为绘图然后将该字典转换为数据帧?任何见解都表示赞赏。我的代码如下:

movie_dict = {}
for movie_index in tqdm(movies_index[0:10]):
    #movie = ia.get_movie(movie_index[2:])
    try:
        movie_dict[movie_index] = ia.get_movie(movie_index[2:])['plot'][0]
    except:
        movie_dict[movie_index] = ''

plots = pd.DataFrame.from_dict(movie_dict, orient='index')
plots.rename(columns={0:'plot'}, inplace=True)
plots


             plot
tt0111161   Two imprisoned men bond over a number of years...
tt0468569   When the menace known as the Joker emerges fro...
tt1375666   A thief who steals corporate secrets through t...
tt0137523   An insomniac office worker and a devil-may-car...
tt0110912   The lives of two mob hitmen, a boxer, a gangst...
tt0109830   The presidencies of Kennedy and Johnson, the e...
tt0120737   A meek Hobbit from the Shire and eight compani...
tt0133093   A computer hacker learns from mysterious rebel...
tt0167260   Gandalf and Aragorn lead the World of Men agai...
tt0068646   The aging patriarch of an organized crime dyna...
pandas imdb imdbpy
1个回答
1
投票

首先,考虑在如此短的时间内进行如此多的查询可能会被视为违反其服务条款:https://www.imdb.com/conditions

但是,对一个主要网站的10.000查询并不能产生任何真正的问题,特别是如果你在每次通话之间等待几秒钟只是为了更好(这需要更长的时间,但在你的情况下这不应该是一个大问题 - 但是再次看到上面关于许可证,你必须尊重)。

我可以建议两种不同的选择:

  1. 使用旧的数据集,可以免费用于个人和非商业用途,IMDbPY能够解析;缺点是数据有点过时(2017年底):https://imdbpy.readthedocs.io/en/latest/usage/ptdf.html
  2. 使用替代来源,如https://www.omdbapi.com/https://www.themoviedb.org/,它应具有公共API和更多许可许可。

免责声明:我是IMDbPY的主要作者之一

© www.soinside.com 2019 - 2024. All rights reserved.