【问题标题】:How to extract text from an HTML file in Google Colab如何在 Google Colab 中从 HTML 文件中提取文本
【发布时间】:2021-01-22 20:32:22
【问题描述】:

我写了一些 html 文件。我想在 colab 中将其用作数据(文本数据)。例如,我想使用<h1> "text "</h1> 中的文本,还需要提取整个班级和这种员工。你能告诉我如何在 google colab 中上传 HTML 文件,然后从这里提取一些文本。 提前致谢

【问题讨论】:

    标签: python html google-colaboratory


    【解决方案1】:

    您可以使用 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')
    

    要上传本地文件,您可以使用左侧文件浏览器面板,如下所示:

    【讨论】:

    • 非常感谢,这肯定是一个解决方案。你知道如何上传文件表单comp,而不用在python中复制HTML代码吗?
    • 当然,我在编辑中添加了一些文件上传指针。
    • 最后一个问题,你知道如何提取无序列表吗?我有这个 unlist 的类名
    猜你喜欢
    • 2018-10-23
    • 1970-01-01
    • 2021-07-02
    • 1970-01-01
    • 2020-09-17
    • 1970-01-01
    • 2020-06-27
    • 1970-01-01
    • 2020-09-27
    相关资源
    最近更新 更多