Python爬虫获取网页编码为“ISO-8859-1”,中文乱码

url = "https://www.tyhttp.com/free/page1/"
response = requests.get(url, verify=False)
response.encoding = response.apparent_encoding
tree=etree.HTML(response.text)
ip_list = tree.xpath('//div[@class="td td-4"]/text()')[3:]
duankou_list = tree.xpath('//div[@class="td td-2"]/text()')[5:]

猜你喜欢

转载自blog.csdn.net/qq_38735017/article/details/126322174