假设我在这里有这个 html:
ul_tags = [u'<p>If you\u2019re in the pet food industry:</p><ul><li>What challenges do you face on a regular basis</li><li>What is your biggest struggle </li></ul>''']
我想将它写入一个文本文件,以便在文件中它看起来类似于它在网页上的样子:
我愿意:
import nltk
import codecs
with codecs.open('test.txt', 'a', encoding="utf8") as file:
for tag in ul_tags:
file.write(nltk.clean_html(tag) + '\n')
当它被写入文件时,它看起来像这样:
如果您从事宠物食品行业:您经常面临哪些挑战 您最大的困难是什么
这只是一行文字。让它看起来像网页上的原始结构的最佳方法是什么?