urllib2在python3后已经合并在urllib中了,具体为urllib.response,urllib.request
urllib2.URLError 改为了urllib.error.URLError
URLError与HTTPError
关于这一点我看了另一个博主的,直接上他的URL吧,点击传送阿谋
下载网页(requests库也可以)
from urllib import request
from urllib import error
'''
urllib2在python3后已经合并在urllib中了,具体为urllib.response,urllib.request
'''
def download(url):
print('Downloading:', url)
try:
html = request.urlopen(url).read()
except error.URLError as e:
print('Download error', e.reason)
html = None
return html
if __name__ == '__main__':
url = 'http://202.115.47.141/'
print(download(url))