您的位置:首页 > 编程语言 > Python开发

python3 urllib.request 按行处理

2016-09-23 15:33 337 查看
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()
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: