马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
import urllib.request
url = 'https://www.biduo.cc/biquge/39_39888/c13353637.html'
headers = {
'Accept-Encoding': 'gzip, deflate, br',
'Accept-Language': 'zh-CN',
'Cache-Control': 'no-cache',
'Connection': 'Keep-Alive',
#'Host': 'www.kanmaoxian.com',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36 Edge/18.18363'
}
res = urllib.request.Request(url=url,headers=headers)
response = urllib.request.urlopen(res)
print(response.read().decode("gbk",'ignore'))
有大佬能帮忙看看这个程序吗,网页是gbk编码的为什么按gbk解码后还是不行
把这个 headers 去掉:'Accept-Encoding': 'gzip, deflate, br' 即可
参考代码:
import urllib.request
url = 'https://www.biduo.cc/biquge/39_39888/c13353637.html'
headers = {
'Accept-Language': 'zh-CN',
'Cache-Control': 'no-cache',
'Connection': 'Keep-Alive',
#'Host': 'www.kanmaoxian.com',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36 Edge/18.18363'
}
res = urllib.request.Request(url=url,headers=headers)
response = urllib.request.urlopen(res)
print(response.read().decode("gbk")
|