junjie 通过本文主要向大家介绍了python urllib2,python3安装urllib2,python3 urllib2,python urllib2下载,python3中urllib2等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com
采集内容常需要得到网页返回的验证码做进一步处理
下面代码是用python写的用来获取网页http状态码的脚本
#!/usr/bin/python
# -*- coding: utf-8 -*-
#encoding=utf-8
#Filename:states_code.py
import urllib2
url = 'http://www.jb51.net/'
response = None
try:
response = urllib2.urlopen(url,timeout=5)
except urllib2.URLError as e:
if hasattr(e, 'code'):
print 'Error code:',e.code
elif hasattr(e, 'reason'):
print 'Reason:',e.reason
finally:
if response:
response.close()
</div>
</div>
您可能想查找下面的文章:
- 【Python】Python的urllib模块、urllib2模块批量进行网页下载文件
- Python网络编程中urllib2模块的用法总结
- Python使用urllib2模块抓取HTML页面资源的实例分享
- Python使用urllib2模块抓取HTML页面资源的实例分享
- 使用Python的urllib2模块处理url和图片的技巧两则
- 使用Python的urllib2模块处理url和图片的技巧两则
- Python中的urllib模块使用详解
- python使用urllib2提交http post请求的方法
- python使用urllib2提交http post请求的方法
- python基于urllib实现按照百度音乐分类下载mp3的方法

