【发布时间】: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 创建一个列表,其中收集了所有“日期时间”?
提前致谢
【问题讨论】:
-
糟糕——stackoverflow.com/q/24197922 是“更深”的副本。仍然:只需使用
print ([a.get('datetime') for a in soup.find_all('time')])
标签: python web-scraping time beautifulsoup datetime-select