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

编码后的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

阿神
阿神

闭关修行中......

Antworte allen(0)
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage