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()
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()
相关文章推荐
- python urllib2处理重定向的问题
- python urllib.request
- python3 urllib.request抓资源的方式
- 在python3.3后urllib2已经不能再用,只能用urllib.request来代替
- 在python3中使用urllib.request编写简单的网络爬虫
- python实例31[urllib.request.urlopen获取股票信息]
- python网络入门:urllib.request模块和urllib.urllib.parse模块
- python3 学习笔记之 urllib.request《二》 (urllib2 in python2)
- python3 学习笔记之 urllib.request《一》 (urllib2 in python2)
- 使用Python的urllib2模块处理url和图片的技巧两则
- python实例31[urllib.request.urlopen获取股票信息]
- python3 urllib.request 网络请求操作
- Python urllib2 设置超时时间并处理超时异常
- Python标准库3.4.3-urllib.request-21.6
- python urllib2 模块异常处理方法
- Python urllib2.urlopen打开中文url的编码处理_Luffy's Space_百度空间
- 处理Python中urllib2/mechanize库进行socket通信超时的问题
- Urllib.request用法简单介绍(Python3.3)
- 【Python】按行读取文件、IOError: [Errno 22] invalid mode ('a+') or filename,处理文件的换行符
- Python自动化测试 (九)urllib2 发送HTTP Request