import requests import os url="http://lofter.nos.netease.com/sogou-Y1gxMDFIeFVHeWhCTkZaMEkzYWx1bGR5WEszQTdRTEZPcndxZWo3Q0dwTG1iZF9uVENpM0tCaUJNOXA1bmZkTA.jpg" root="F://pics//"; path=root+url.split('/')[-1] try: if not os.path.exists(root): os.mkdir(root) if not os.path.exists(path): r=requests.get(url) with open(path,'wb') as f: f.write(r.content) f.close() print("圖片保存cg") else: print("保存失敗") except: print('爬取失敗')
2、在windows終端執行以上代碼