美文网首页
lxml提取html标签内容, tostring()不能显示中文

lxml提取html标签内容, tostring()不能显示中文

作者: modingfa | 来源:发表于2019-04-28 21:31 被阅读0次

from lxml import etree
import requests

response = requests.get('https://www.baisu.com/).text
tree = etree.HTML(response)
strs = tree.xpath( "//body")
strs = strs[0]

strs = (etree.tostring(strs)) ########### 不能正常显示中文################

strs = (etree.tostring(strs, encoding = "utf-8", pretty_print = True, method = "html")) # 可以正常显
示中文
print (strs)

相关文章

网友评论

      本文标题:lxml提取html标签内容, tostring()不能显示中文

      本文链接:https://www.haomeiwen.com/subject/cxlsnqtx.html