【发布时间】:2021-01-22 20:32:22
【问题描述】:
我写了一些 html 文件。我想在 colab 中将其用作数据(文本数据)。例如,我想使用<h1> "text "</h1> 中的文本,还需要提取整个班级和这种员工。你能告诉我如何在 google colab 中上传 HTML 文件,然后从这里提取一些文本。
提前致谢
【问题讨论】:
标签: python html google-colaboratory
我写了一些 html 文件。我想在 colab 中将其用作数据(文本数据)。例如,我想使用<h1> "text "</h1> 中的文本,还需要提取整个班级和这种员工。你能告诉我如何在 google colab 中上传 HTML 文件,然后从这里提取一些文本。
提前致谢
【问题讨论】:
标签: python html google-colaboratory
您可以使用 IPython.display.HTML 帮助器呈现 HTML。
然后,使用 google.colab.output 中的 eval_js 帮助器来抓取呈现的 HTML 中的文本。
这是full example:
这里复制关键代码:
from IPython.display import HTML, display
from google.colab import output
# Render the HTML.
display(HTML(open('example.html').read()))
html_text = output.eval_js('document.body.innerText')
【讨论】: