我正在運行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()' –