• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell
您的位置:首页 > 脚本语言 >python > python中使用urllib2获取http请求状态码的代码例子

python中使用urllib2获取http请求状态码的代码例子

作者:junjie 字体:[增加 减小] 来源:互联网

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的方法

相关文章

  • python检测服务器是否正常
  • Python3基础之list列表实例解析
  • Python功能键的读取方法
  • Python中__init__.py文件的作用详解
  • Python计算字符宽度的方法
  • python自动zip压缩目录的方法
  • python实现RSA加密(解密)算法
  • Python中文件I/O高效操作处理的技巧分享
  • 详细解读Python的web.py框架下的application.py模块
  • CentOS下使用yum安装python-pip失败的完美解决方法

文章分类

  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell

最近更新的内容

    • 解析Python中while true的使用
    • python 快速排序代码
    • Python打包可执行文件的方法详解
    • 使用python绘制常用的图表
    • python字典基本操作实例分析
    • Python HTTP客户端自定义Cookie实现实例
    • 使用PyCharm配合部署Python的Django框架的配置纪实
    • Python中函数的参数传递与可变长参数介绍
    • 一波神奇的Python语句、函数与方法的使用技巧总结
    • Python-基础-入门 简介

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有