request get/post返回乱码

注销设置Accept-Encoding为gzip,deflate,返回的网页是乱码
����g�/1�C�y�/�D�O��’��

‘Accept-Encoding’: ‘gzip, deflate, br’

request get/post返回乱码_第1张图片
去掉后面的br或者 注释Accept-Encoding

 import requests

class InfoTec(object):

    def __init__(self):

        self.headers = {
            'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3',
            # 'Accept-Encoding': 'gzip, deflate, br',
            'Accept-Language': 'zh-CN,zh;q=0.9',
            'Cache-Control': 'max-age=0',
            'Connection': 'keep-alive',
            'Cookie': 'whioqwedqowi',
            'Host': 'www.tripadvisor.cn',
            'Upgrade-Insecure-Requests': '1',
            'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36'
        }
        
    def li_index_page(self):
        url = 'https://www.tripadvisor.cn/Attractions-g294220-Activities-Nanjing_Jiangsu.html'# + 'http://dcs.conac.cn/js/33/000/0000/60573107/CA330000000605731070005.js'
        response = requests.get(url, headers=self.headers)
        return response.text
        
    def run(self):
        res = self.li_index_page()
        print(res)

if __name__ == '__main__':
    infotec = InfoTec()
    infotec.run()

其它类型的乱码(转码)

request get/post返回乱码_第2张图片

你可能感兴趣的:(p爬虫)