python使用urllib2抓取网页时的错误处理,pythonurllib2,try: urlf


try:    urlfile = urllib2.urlopen('http://sebsauvage.net/nonexistingpage.html')except urllib2.HTTPError, exc:    if exc.code == 404:        print "Not found !"    else:                   print "HTTP request failed with error %d (%s)" % (exc.code, exc.msg)except urllib2.URLError, exc:    print "Failed because:", exc.reason

评论关闭