import json
from lxml import etree
html = """
网页代码
"""
parse_html = etree.HTML(html)
ls = []
i = 1
while i <= 10:
index = parse_html.xpath("/html/body/li/div/div[%d]/div[2]/div/div[2]/a/i[1]/text()" % i)
ls.append(index)
i += 1
print(ls)
with open('wordcloud.txt', 'w', encoding='utf-8') as f:
f.write(json.dumps(ls))
# Now read the file back into a Python list object
with open('wordcloud.txt', 'r', encoding='utf-8') as f:
ls = json.loads(f.read())
这是导入txt的内容
[["\u6813Q\uff08\u6211\u771f\u7684\u4f1a\u8c22\uff09"], ["PUA\uff08CPU/KTV/ICU/PPT\uff09"],
有没有人能帮帮我