欢迎访问悦橙教程(wld5.com),关注java教程。悦橙教程  java问答|  每日更新
页面导航 : > > > 文章正文

lxml提取html标签内容, tostring()不能显示中文 解决方案,lxmltostring

来源: javaer 分享于  点击 43987 次 点评:264

lxml提取html标签内容, tostring()不能显示中文 解决方案,lxmltostring


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)

相关文章

    暂无相关文章

用户点评