conn.read()返回的是bytes,
bytes转换成字符串用decode.
import urllib.request
url = 'http://www.baidu.com'
conn = urllib.request.urlopen(url)
for html in conn.readlines():
page = html.decode('UTF-8')
if 'title=' in page:
print(page)
conn.close()
conn.read()返回的是bytes,
bytes转换成字符串用decode.
import urllib.request
url = 'http://www.baidu.com'
conn = urllib.request.urlopen(url)
for html in conn.readlines():
page = html.decode('UTF-8')
if 'title=' in page:
print(page)
conn.close()