advancerHF
advancerHF
采纳率33.3%
2020-08-21 10:25

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'))

图片说明

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

2条回答

相关推荐