lxml extrait le contenu des balises html, tostring () ne peut pas afficher la solution chinoise

 

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")).decode("gbk") # 可以正常显示中文
print (strs)

 

Publié 150 articles originaux · loué 149 · 810 000 vues

Je suppose que tu aimes

Origine blog.csdn.net/chaishen10000/article/details/103168859
conseillé
Classement