【发布时间】:2017-07-15 11:11:54
【问题描述】:
我正在运行 python 3.5 并试图从该网页中提取 BINGO 数据,但遇到了一些问题。当我拆分 html 响应时,我一直在我的字符串列表之前收到字母 b,这使得无法检查。我检查了我不熟悉的 html 输出及其类字节。为什么这个 b 在我所有的字符串之前,第二个我怎样才能更干净地解析一个 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">Renew' b'Board' b'Contract
' b'Copyright' b'1996-2013' b''
【问题讨论】:
-
因为 response.read 返回
bytes不再是str。使用encode()
标签: python html python-3.x parsing urllib