【问题标题】:Problem: how to get a list of tag attribute values with beautifulsoup问题:如何用beautifulsoup获取标签属性值列表
【发布时间】:2020-05-16 15:30:13
【问题描述】:

我想从当地电影院的网站上抓取并获取所有时间,当某部电影正在运行时。

我找到了以下表格中列出时间的表格:

[<time datetime="2020-01-31T21:15:00+01:00">21:15</time>].

如果我使用 beautifulsoup 作为 x.find_all('time')。我总是以上面显示的形式获得所有时间。 但我只想要 'datetime' 所以在这种情况下 2020-01-31T21: 15: 00 + 01: 00. 现在当我搜索 x.find_all('time')['datetime' ] 我收到以下错误:

TypeError: list indices must be integers or slices, not str

谁能告诉我如何使用 beautifulsoup 创建一个列表,其中收集了所有“日期时间”?

提前致谢

【问题讨论】:

标签: python web-scraping time beautifulsoup datetime-select


【解决方案1】:
x.find_all('time')

将返回一个列表。因此,您必须先从列表中获取一个项目,然后才能获取“日期时间”属性。

x.find_all('time')[0]['datetime']

可能会这样做。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-19
    • 1970-01-01
    • 1970-01-01
    • 2013-09-14
    • 2017-10-09
    相关资源
    最近更新 更多