您的位置:首页技术文章
文章详情页

网页爬虫 - Python爬虫返回状态码与实际情况不符?

【字号: 日期:2022-09-03 18:57:11浏览:119作者:猪猪

问题描述

import urllib2opener = urllib2.build_opener()html = Noneresponse = Noneresponse = opener.open(’http://www.sxxrcs.com/was5/web/’)html = response.codeprint html

比如这个爬虫,输出状态码是200。

网页爬虫 - Python爬虫返回状态码与实际情况不符?

可是直接访问http://www.sxxrcs.com/was5/web/是404,抓包响应的也是404,请问这是为什么?

网页爬虫 - Python爬虫返回状态码与实际情况不符?

问题解答

回答1:

用requests吧

import requestsr = requests.get(’http://www.sxxrcs.com/was5/web/’)print r.status_codeprint r.text回答2:

200正常啊,requests方便快捷。

标签: Python 编程
相关文章: