urllib2抓取网页时的错误处理,urllib2抓取网页,try: urlf


try:    urlfile = urllib2.urlopen('<a href="http://sebsauvage.net/nonexistingpage.html">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#该片段来自于http://byrx.net

评论关闭