python使用整理

1.发生5xx错误时重复请求方法

def reqURL(url,num=2):
try:
     html=urllib2.urlopen(url).read()
except urllib2.URLError as e:
     html=None
        if num >0:
          if hasattr(e,'code') and 500 <=e.code <600:
            return reqURL(url,num-1)

猜你喜欢

转载自blog.csdn.net/weixin_43002236/article/details/81806971