python - 如何在python中将html转换为文本?

标签 python html python-3.x beautifulsoup

有没有办法在Python中将html转换为文本。我正在寻找干净的文本,应该有适当的间距和新行。

我尝试过 BeautifulSoup,但我看到了如下所示的重叠文本。

from bs4 import BeautifulSoup
html = """Html code"""
soup = BeautifulSoup(html,'lxml')   
print(soup.get_text())

我得到以下输出

Retrieving image informationConverting image formatsScaling, cropping, and rotating imagesAdding image, text, and....

但是这应该被适本地间隔(粗体)。

还有其他模块吗?

HTML Source .

最佳答案

see this snap shot

试试这个代码,你只会得到文本。

汤 = BeautifulSoup(html,"html5lib") 文本 = soup.get_text(strip=True)

关于python - 如何在python中将html转换为文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47089570/

相关文章:

python - 在 PyCharm 社区版中运行 Python 3 解释器

javascript - 如何定位动态内容,使其他内容不移动

python-3.x - 如何使用 timeit 对函数进行计时并保存结果

大 float 的Python总和

python - 只从 python nose 运行 doctests

html - SVG反向绘制css动画跨浏览器

javascript - 无法通过的边界( Canvas 游戏)

html - 如何使用 BeautifulSoup 在 Python 中隔离只有一到两位数的解析结果

python - Django InlineModelAdmin : Show partially an inline model and link to the complete model

python - 有没有更好的方法用 kwargs 更新对象的 __dict__ ?