问题有点多,感谢你的耐心解答!
import urllib.request
from urllib.error import URLError,HTTPError,ContentTooShortError
def download(url,cishu=2):
print ('Downloading:',url)
try:
html=urllib.request.urlopen (url).read()
except (URLError,HTTPError,ContentTooShortError)as e:
print ('Download error:',e.reason) # e.reason是什么?
html=None # 为什么要设置为None?
if cishu>0:
if hasattr(e,"code") and 500 <= e.code < 600: #"code"是什么 ?
return download(url,cishu-1) #它返回的是一个函数的调用,是覆盖了原本的download(url,cishu=2),还是对download(url,cishu=2)复制,创建一个新函数?
return html