在王者榮耀官網下載所有英雄皮膚圖片
過程分析
我們仍然需要herolist.json進行輔助,進一步找到英雄皮膚圖片對應的url,然後把圖片下載下來,保存在一個文件夾裡。在王者榮耀官網任意進入一個英雄的資料頁,打開開發者工具,找到xxx-bigskin-x.jpg, xxx對應的是英雄編號,x對應的是皮膚的編號。這裡我進入的是鍾馗的主頁,找到175-bigskin-x.jpg,找到它的url無私分享全套Python爬蟲乾貨,如果你也想學習Python,@ 私信小編獲取
完整代碼
<code>import
urllib.requestimport
jsonimport
os response = urllib.request.urlopen("http://pvp.qq.com/web201605/js/herolist.json"
) hero_json = json.loads(response.read()) hero_num = len(hero_json) save_dir ='heroskin/'
if
not
os.path.exists(save_dir): os.mkdir(save_dir)for
iin
range(hero_num): skin_names = hero_json[i]['skin_name'
].split('|'
)for
cntin
range(len(skin_names)): save_file_name = save_dir + str(hero_json[i]['ename'
]) +'-'
+ hero_json[i]['cname'
] +'-'
+ skin_names[cnt] +'.jpg'
skin_url ='http://game.gtimg.cn/images/yxzj/img201606/skin/hero-info/'
+str(hero_json[i]['ename'
])+'/'
+str(hero_json[i]['ename'
]) +'-bigskin-'
+ str(cnt+1
) +'.jpg'
if
not
os.path.exists(save_file_name): urllib.request.urlretrieve(skin_url, save_file_name) /<code>
結果展示
為了幫助大家更輕鬆的學好Python,我給大家分享一套Python學習資料,希望對正在學習的你有所幫助!
獲取方式:關注並私信小編 “ 學習 ”,即可免費獲取!