import urllib.request while True: def photo(x,y): try: a = urllib.request.urlopen(str(x)) b = a.read() with open(str(y),'wb')as f: f.write(b) print('操作成功!') except ValueError as reason: print('你的图片网址或存放地址错误!') a = str(input('请输入你要下载的图片的网址:')) b = str(input(r'请输入你要存放图片的地址:')#如果要在Desktop上爬到一个图片,那么记住Desktop后还有\ c = str(input('请输入图片名字:')) d = str(b+str(c)+str('.jpg')) print(photo(a,d))