Python 爬虫编码格式问题 gb2312转换utf8

遇到的问题是:爬取网页得到的结果如下(部分)  里面的中文出现乱码。

  

<!DOCTYPE html>
<html lang='zh-CN'>
<head>
<meta charset='gb2312'>
<meta content='IE=edge' http-equiv='X-UA-Compatible'>
<title>2017Äê11ÔÂ10ÈÕÃâ·Ñ´úÀíip µÚ1Ò³</title>
<meta name="keywords" content="´úÀíip£¬´úÀíip¼ì²â£¬´úÀíipÑéÖ¤£¬¿ÉÓôúÀíip£¬×îдúÀíip£¬½ñÈÕ¿ÉÓôúÀíip£¬Ãâ·Ñ´úÀíip">
<meta name="description" content="ip181ÊÇÒ»¼ÒרΪ´úÀíipʹÓÃÕß´òÔìµÄ´úÀíip¼ì²âƽ̨£¬ÕâÀï²»½öÌṩרҵµÄ´úÀíipÑéÖ¤·þÎñ£¬»¹ÎªÄúÌṩ×îеÄÃâ·Ñ´
úÀíip£¬ÊµÊ±¸üдúÀíip¡£
"> <link href="/ip181.css" media="all" rel="stylesheet" /> </head> <body> <style> .gx{ font-size:14px;color:#666666;margin-left:10px;font-weight:100;

这是 

print response.encoding   

输出结果是 ISO-8859-1


使用的方法是
print response.text.encode('ISO-8859-1').decode(requests.utils.get_encodings_from_content(response.text)[0])

结果:

<!DOCTYPE html>
<html lang='zh-CN'>
<head>
<meta charset='gb2312'>
<meta content='IE=edge' http-equiv='X-UA-Compatible'>
<title>2017年11月10日免费代理ip 第1页</title>
<meta name="keywords" content="代理ip,代理ip检测,代理ip验证,可用代理ip,最新代理ip,今日可用代理ip,免费代理ip">
<meta name="description" content="ip181是一家专为代理ip使用者打造的代理ip检测平台,这里不仅提供专业的代理ip验证服务,还为您提供最新的免费代理ip,实时更新代理ip。">
<link href="/ip181.css" media="all" rel="stylesheet" />
</head>
<body>
<style>

 













 

转载于:https://www.cnblogs.com/xuchunlin/p/7814932.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值