How to Scrape and Download All King of Glory Hero Skins with Python
This tutorial walks you through using Python's requests, lxml, and JSON parsing to automatically crawl the King of Glory website, extract hero skin URLs, and download the images into organized folders while displaying progress in the console.
Introduction
King of Glory (Wangzhe Rongyao) is a popular game with many hero skins that can be used as wallpapers. This tutorial shows how to use Python to crawl and download these skins.
Project Goal
Create a folder to store hero skins categorized by hero, and display download results in the console.
Preparation
Software: PyCharm. Required libraries: requests, lxml, fake_useragent, json, os.
Target website example: https://www.555x.org/html/wuxiaxianxia/list_29_{}.html
Analysis
1. Open the official King of Glory website and go to hero details.
2. Use browser dev tools (F12) to inspect hero links.
3. Observe URL pattern such as herodetail/531.shtml; the numeric part identifies the hero.
4. In the Network tab, find herolist.json and download it.
5. The JSON contains fields ename (hero identifier), cname (hero name), and skin_name (skin name).
6. Hero detail pages reveal image URLs such as
http://game.gtimg.cn/images/yxzj/img201606/skin/hero-info/107/107-bigskin-1.jpg.
http://game.gtimg.cn/images/yxzj/img201606/skin/hero-info/{}/{}-bigskin-{}.jpgImplementation
Define a class wzry with an __init__ method that creates the main folder, and a main method to run the workflow.
import requests, json, os
from lxml import etree
from fake_useragent import UserAgent
class wzry(object):
def __init__(self):
os.mkdir("王者") # create folder (run only once)
def main(self):
pass
if __name__ == '__main__':
Siper = wzry()
Siper.main()Parse herolist.json:
def wzry(self):
response = requests.get('https://pvp.qq.com/web201605/js/herolist.json', headers=self.headers)
content = response.text
data = json.loads(content)
def main(self):
self.wzry()Iterate over heroes, create subfolders, request hero detail page, extract skin names with XPath, construct image URLs, download images, and save them.
for i in data:
hero_number = i['ename']
hero_name = i['cname']
os.mkdir(f"./王者荣耀/{hero_name}")
response_src = requests.get(f"https://pvp.qq.com/web201605/herodetail/{hero_number}.shtml", headers=self.headers)
hero_content = response_src.content.decode('gbk')
hero_data = etree.HTML(hero_content)
hero_img = hero_data.xpath('//div[@class="pic-pf"]/ul/@data-imgname')
hero_src = hero_img[0].split('|')
for i in range(len(hero_src)):
i_num = hero_src[i].find("&")
skin_name = hero_src[i][:i_num]
response_skin = requests.get(
f"https://game.gtimg.cn/images/yxzj/img201606/skin/hero-info/{hero_number}/{hero_number}-bigskin-{i+1}.jpg")
skin_img = response_skin.content
with open(f"./王者荣耀/{hero_name}/{skin_name}.jpg", "wb") as f:
f.write(skin_img)
print(f"{skin_name}.jpg 下载成功!!")Result
Running the script creates a folder “王者荣耀” with subfolders for each hero, each containing the downloaded skin images. The console prints success messages.
Conclusion
Avoid excessive crawling to reduce server load.
The project demonstrates basic JSON parsing, string formatting, and use of the format function.
Hands‑on practice helps deepen understanding of web scraping with Python.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Python Crawling & Data Mining
Life's short, I code in Python. This channel shares Python web crawling, data mining, analysis, processing, visualization, automated testing, DevOps, big data, AI, cloud computing, machine learning tools, resources, news, technical articles, tutorial videos and learning materials. Join us!
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
