import requests import os root = "C://Users//-PC//Desktop//python//" try: for x in range(1,5): url = 'http://game.gtimg.cn/images/yxzj/img201606/skin/hero-info/142/142-bigskin-{0}{1}'.format(x,'.jpg') path = root + url.split("/")[-1] if not os.path.exists(root): os.mkdir(root) if not os.path.exists(path): r = requests.get(url) r.raise_for_status() with open(path,"wb") as f: f.write(r.content) print("爬取完成") else: print("文件已存在") except Exception as e: print("爬取失败" + str(e))