【发布时间】:2018-11-10 15:28:09
【问题描述】:
我有下面的 html 代码,我正在尝试将 3:40 提取为文本以在我的 python 脚本中使用。我将如何获取这些信息?
【问题讨论】:
-
不放图,写代码。
-
你在用什么? XPath?
我有下面的 html 代码,我正在尝试将 3:40 提取为文本以在我的 python 脚本中使用。我将如何获取这些信息?
【问题讨论】:
我会使用BeautifulSoup 库。在知道您已经拥有 HTML 文件的情况下,我将通过以下方式获取此信息:
from bs4 import BeautifulSoup
with open(html_path) as html_file:
html_page = BeautifulSoup(html_file, 'html.parser')
div = html_page.find('div', class_='playbackTimeline__duration')
span = div.find('span', {'aria-hidden': 'true'})
text = span.get_text()
我不确定它是否有效,但它可以让您了解如何执行此类操作。如果您想了解更多信息,请检查“网络抓取”。 :)
【讨论】: