Python3.7的Tornado框架,调用HTTPClient获取网页信息,控制台为什么会报乱码?

不管是get还是post请求,获取到页面都会报下图乱码,望各位兄弟姐妹帮帮忙。

from tornado.httpclient import HTTPClient,HTTPRequest

def getRequest(url,):

httpclient = HTTPClient()

response = httpclient.fetch(url)

return response.body

def postRequest(request):

httpclient = HTTPClient()

response = httpclient.fetch(request)

return response.body

request = HTTPRequest(url='http://www.baidu.com',method='POST',headers={'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.87 Safari/537.36 SLBrowser/6.0.1.8131'},body='uname=wang')

print(postRequest(request))

# print(getRequest('http://www.baidu.com'))

图片说明

回答

print(postRequest(request).decode('utf-8'))

https://www.cnblogs.com/xiaoqi/p/5101795.html

以上是 Python3.7的Tornado框架,调用HTTPClient获取网页信息,控制台为什么会报乱码? 的全部内容, 来源链接: utcz.com/a/40006.html

回到顶部