爬虫时返回的结果的中文是这样的, 如何将&语
格式的字符转换为中文?
代码如下:
from requests import get
from lxml.etree import HTML, tostring
headers = {
"User-Agent": """Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 \
(KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36"""
}
url = "https://ask.csdn.net/ask"
req = get(url,headers=headers)
text=req.content.decode('utf-8')
tree = HTML(text)
ques = tree.xpath('//*[@id="floor-ask-content-index_493"]/div/div/div[2]/div/div/div[1]/a/h2')
print(tostring(ques[0],method="html"))