首页  >  问答  >  正文

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

import urllib2

opener = urllib2.build_opener()

html = None
response = None

response = opener.open('http://www.sxxrcs.com/was5/web/')
html = response.code
print html

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

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

黄舟黄舟2740 天前596

全部回复(2)我来回复

  • 伊谢尔伦

    伊谢尔伦2017-04-18 10:26:31

    用requests吧

    import requests
    
    r = requests.get('http://www.sxxrcs.com/was5/web/')
    print r.status_code
    print r.text

    回复
    0
  • 高洛峰

    高洛峰2017-04-18 10:26:31

    200正常啊,requests方便快捷。

    回复
    0
  • 取消回复