日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

lxml提取html標簽內容, tostring()不能顯示中文 解決方案

作者:柴神 更新時間: 2022-02-05 編程語言

?

from lxml import etree
import requests


response = requests.get('https://www.baisu.com/).text
tree = etree.HTML(response)
strs = tree.xpath( "http://body")
strs = strs[0]
 strs = (etree.tostring(strs)) # 不能正常顯示中文
strs = (etree.tostring(strs, encoding = "utf-8", pretty_print = True, method = "html")).decode("gbk") # 可以正常顯示中文
print (strs)

?

原文鏈接:https://blog.csdn.net/chaishen10000/article/details/103168859

欄目分類
最近更新