有没有办法从扮演多个角色的演员那里检索剧集计数和日期?

如何解决有没有办法从扮演多个角色的演员那里检索剧集计数和日期?

更清楚一点:我想检索一个演员在 IMDB 中显示系列有多少集(带有日期)。

I'm using the Doctor Who page as an example

Cast for Doctor Who

在这种情况下,我想知道马特史密斯从 2010 年到 2020 年出现了 46 集。

IMDB 在角色对象上完美地做到了这一点,具有 currentRole 和它的 notes 属性

from imdb import IMDb

ia = IMDb()
movie = ia.get_movie('0436992') # id for Doctor Who
cast = movie['cast']
print("Actor name :",cast[0]['name'])
print("Role :",cast[0].currentRole)
print("Notes :",cast[0].notes)

显示

Actor name : Matt Smith
Role : The Doctor
Notes : (58 episodes,2010-2020)

(奇怪的是,剧集数错了,因为网站上写了 46 集,如果你点击它会显示 54 集,但这不是我的观点)

然而,其他演员在这个系列中扮演了多个角色,Character.currentRole 则返回一个列表。我更改了代码以正确获取它:


from imdb import IMDb

ia = IMDb()
movie = ia.get_movie('0436992')
cast = movie['cast']

for i in range(2):

    print("Actor name :",cast[i]['name'])

    if isinstance(cast[i].currentRole,list):
        print("Roles :")
        for role in cast[i].currentRole:
            print(" - ",role," (Note :" + role.notes + ")")

    else:
        print("Role :",cast[i].currentRole)
    print("Notes :",cast[i].notes)
    print("")

但结果是:

Actor name : Matt Smith
Role : The Doctor
Notes : (58 episodes,2010-2020)

Actor name : David Tennant
Roles :
 -  The Doctor  (Note :)
 -  ...  (Note :)
Notes :

我无法在此处检索我想要的信息,并且所有“注释”都是空的。我在调试时尝试从 imdbpy 中挖掘 Person 和 Character 对象,但找不到我需要的东西。

它似乎只发生在扮演多个角色的演员身上,有没有办法用 imdbpy 来检索它,而不是外部解析器?

任何想法都值得赞赏

解决方法

我遇到了同样的问题。遗憾的是,我也无法用 IMDbPY 解决它。我认为它是越野车。 相反,我用 bs4 编写了自己的解析器:

import requests
from bs4 import BeautifulSoup

# parse the page with bs4
page = requests.get('https://www.imdb.com/title/tt0436992/fullcredits')
soup = BeautifulSoup(page.text,'lxml')

# find the cast table
table = soup.find('table',{"class": "cast_list"})

cast = []

# iterate over it
for row in table.find_all('tr'):
    column_marker = 0
    columns = row.find_all('td')
    cast_member = {}
    for column in columns:
        # name column
        if column_marker == 1:
            cast_member['name'] = column.get_text().strip()
        # combined role and episodes/years column
        elif column_marker == 3:
            links = column.find_all('a')
            role_element = column.find('a',{'class': None})
            if role_element:
                cast_member['role'] = role_element.get_text().strip()
            episodes_and_years_element = column.find('a',{'class': 'toggle-episodes'})
            if episodes_and_years_element:
                episodes_and_years = episodes_and_years_element.get_text().strip().split(',')
                cast_member['episodes'] = episodes_and_years[0]
                if len(episodes_and_years) > 1:
                    cast_member['years'] = episodes_and_years[1]
        column_marker += 1
    if len(cast_member):
        cast.append(cast_member)

print(cast[:5])

这绝对不是最优雅的解决方案,但我相信它可以满足您的需求。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?
Java在半透明框架/面板/组件上重新绘画。
Java“ Class.forName()”和“ Class.forName()。newInstance()”之间有什么区别?
在此环境中不提供编译器。也许是在JRE而不是JDK上运行?
Java用相同的方法在一个类中实现两个接口。哪种接口方法被覆盖?
Java 什么是Runtime.getRuntime()。totalMemory()和freeMemory()?
java.library.path中的java.lang.UnsatisfiedLinkError否*****。dll
JavaFX“位置是必需的。” 即使在同一包装中
Java 导入两个具有相同名称的类。怎么处理?
Java 是否应该在HttpServletResponse.getOutputStream()/。getWriter()上调用.close()?
Java RegEx元字符(。)和普通点?