我正在运行python 3.5,并试图从此网页中提取BINGO数据,并遇到一些问题。当我拆分html响应时,我不断收到字母b之前的字符串列表,并使其无法检查。我检查了我不熟悉的html输出及其类字节。为什么这个b在我所有的字符串之前,第二我怎么能更干净地解析一个html页面。在python 3.5中解析html会返回奇怪的类型
import urllib.request
with urllib.request.urlopen('http://www.executiveadministrator.com/cgi-local/inoutPROhosted4/inoutPRO.pl?refresh=1&ID=AFTCO') as response:
html = response.read()
htmllist = html.split()
print(htmllist)
for i in htmllist:
#if i == 'BINGO':
print(i)
示例输出:b'class = “colorlinkbody”>续订 'b'Board' b'Contract
'b'Copyright' b'1996-2013' B ''
因为response.read返回'字节'不再'str'。使用'encode()' –