python3.6解码问题

2025-04-29 02:29:33
推荐回答(4个)
回答1:

import urllib.request
html=urllib.request.urlopen("http://v.liangle.com/nba").read()
decodedHtml=html.decode('utf-8')
##完成
import requests
resp=urllib.get("http://v.liangle.com/nba")
resp.encoding='utf-8'
decodedHtml=resp.text
##完成

回答2:

报错哪一行改成这样
html.encoding = 'utf8'

回答3:

不用decode,直接BeautifulSoup

回答4:

这里获取 html 以后直接
soup = BeautifulSoup(html.content, 'lxml') # 不要使用 text 由 BS4 自动处理编码