Home > Backend Development > Python Tutorial > python获取网页状态码示例

python获取网页状态码示例

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-16 08:44:40
Original
1412 people have browsed it

代码很简单,只需要2行代码就可实现想要的功能,虽然很短,但确实使用,主要使用了requests库。

测试2XX, 3XX, 4XX, 5XX都能准确识别。

复制代码 代码如下:

#coding=utf-8

import requests

def getStatusCode(url):
 r = requests.get(url, allow_redirects = False)
 return r.status_code
print getStatusCode('http://www.jb51.net/')

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template