|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
import urllib.request
import urllib.parse
url ='http://bbs.fishc.com/'
req = urllib.request.Request(url)
req.add_header('User-Agent','Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36')
response = urllib.request.urlopen(req)
html =response.read().decode('utf-8')
print (html)
为什么解码之后会报错?
提示:
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
url_open('http://jandan.net/')
File "C:\Users\Administrator\Desktop\m1.py", line 11, in url_open
html =response.read().decode('utf-8')
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc3 in position 313: invalid continuation byte
<meta http-equiv="Content-Type" content="text/html; charset=gbk" />
import urllib.request
import urllib.parse
url ='http://bbs.fishc.com/'
req = urllib.request.Request(url)
req.add_header('User-Agent','Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36')
response = urllib.request.urlopen(req)
html =response.read().decode('gbk')
print (html)
|
|