【发布时间】:2017-10-10 17:53:32
【问题描述】:
我有一个名为 BBC_news_home.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,更具体地说是.get_text()。
标签: python html text information-retrieval data-extraction