python - BeautifulSoup报错input conversion failed due to input error
阿神
阿神 2017-04-17 14:21:56
0
0
1714

编码后的html:

def getHtml(self,url):
    headers = {
        "User-Agent": "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:34.0) Gecko/20100101 Firefox/34.0",
        "Connection":"keep-alive",
    }
    r = requests.get(url,headers=headers)
    html = r.text.encode(r.encoding)
    return html

执行
bs = BeautifulSoup(html)

结果报错如下;

encoding error : input conversion failed due to input error, bytes 0xAC 0xE5 0x8F 0xB8

Unicode的hmtl:

def getHtml(self,url):
    headers = {
        "User-Agent": "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:34.0) Gecko/20100101 Firefox/34.0",
        "Connection":"keep-alive",
    }
    r = requests.get(url,headers=headers)
    html = r.text
    return html

执行
bs = BeautifulSoup(html)
结果报错如下;

encoding error : input conversion failed due to input error, bytes 0xA1 0x6C 0x09 0x67

阿神
阿神

闭关修行中......

全部回覆(0)
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板