我正在使用 beautifulsoup 转换 html 数据,收集“p”标签中的所有文本并将其转换为字符串。我这样做是使用:
source = BeautifulSoup(response.text, "html.parser")
content = ""
for section in source.findAll('p'):
content += section.get_text()
但是,当我转换它时,上面提到的标签分散在整个字符串中。我尝试了多种方法从我正在使用的字符串中删除所有这些字符,例如:
unicodedata.normalize('NFKC', text)
content = u" ".join(content.split())
text.strip(), text.rstrip()
是否有可以从字符串中删除这些标签的库。其中一些方法解决了一些问题,但大多数仍然存在。
编辑:这是一个字符串示例:https ://pastebin.com/2DGECKXa
摇曳的蔷薇
森栏
相关分类