0

我将 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)。所以解决这个问题的方法是让它在一夜之间运行。还有其他解决方案吗?此外,有没有比我目前用键作为电影索引(例如“肖申克救赎”的 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...
4

1 回答 1

2

首先,考虑在这么短的时间内进行这么多的查询可能会违反他们的服务条款: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 的主要作者之一

于 2019-02-28T22:15:25.717 回答