0
我有一个名为BBC_news_home.html的文件,我需要删除所有标记标记,所以我留下的只是一些文本。到目前为止,我有:Python - 删除标记标签并从文件中读取html?
def clean_html(html):
cleaned = ''
line = html
pattern = r'(<.*?>)'
result = re.findall(pattern, line, re.S)
if result:
f = codecs.open("BBC_news_home.html", 'r', 'utf-8')
print(f.read())
else:
print('Not cleaned.')
return cleaned
我与regex101.com检查的模式是正确的我只是不知道如何打印输出,以检查是否标记标签都没有了?
您可能想查看[BeautifulSoup](https://www.crummy.com/software/BeautifulSoup/bs4/doc/),更具体地说[.get_text()](https://www.crummy。 COM /软件/ BeautifulSoup/BS4/DOC /#获取文本)。 –