文章详情页
网页爬虫 - Python爬虫返回状态码与实际情况不符?
浏览:109日期:2022-09-03 18:57:11
问题描述
import urllib2opener = urllib2.build_opener()html = Noneresponse = Noneresponse = opener.open(’http://www.sxxrcs.com/was5/web/’)html = response.codeprint html
比如这个爬虫,输出状态码是200。
可是直接访问http://www.sxxrcs.com/was5/web/是404,抓包响应的也是404,请问这是为什么?
问题解答
回答1:用requests吧
import requestsr = requests.get(’http://www.sxxrcs.com/was5/web/’)print r.status_codeprint r.text回答2:
200正常啊,requests方便快捷。
相关文章:
1. index.php错误,求指点2. Docker for Windows10 配置共享文件夹失败该如何解决?3. 运行python程序时出现“应用程序发生异常”的内存错误?4. 语法错误,意外’:’5. mysql - 要取出数据库中按某字段排序后的前10,20,30条数据要怎么做?6. 关于mysql unique的问题,如图所示7. python局部变量的问题8. c++ - pycharm 4.5 的 python -> preferences 找不到9. android - Windows系统下运行react-native App时,报下面的错误?10. mysql - inner join和left join的效率问题
排行榜