How to Scrape Game Hero Skins with Python: Step‑by‑Step Guide
This tutorial demonstrates how to use Python to crawl official game websites of League of Legends, Honor of Kings, and Smite, extracting hero skin images by locating hero IDs, constructing image URLs, and downloading the files, providing complete code examples for both direct URL extraction and pattern‑based downloading.
Overview
This article shows how to write a Python web‑scraper to download hero skin images from the official sites of three popular MOBA games: Honor of Kings (王者荣耀), League of Legends (英雄联盟), and Smite (神之浩劫). The goal is to obtain the large‑size skin pictures for personal use.
Honor of Kings (王者荣耀)
1. Open the All Heroes list page and use the browser developer tools to locate a JSON file that maps each hero to a numeric ID.
2. Parse the JSON to extract two parallel lists: hero_name (Chinese names) and hero_number (numeric IDs).
#爬取王者荣耀英雄图片
#导入所需模块
import requests
import re
import os
url='http://pvp.qq.com/web201605/js/herolist.json'
head={'User-Agent':'换成你自己的head'}
html=requests.get(url,headers=head)
html_json=html.json()
hero_name=list(map(lambda x:x['cname'],html_json))
hero_number=list(map(lambda x:x['ename'],html_json))3. For each hero, construct the image URL pattern:
http://game.gtimg.cn/images/yxzj/img201606/skin/hero-info/'+str(v)+'/'+str(v)+'-bigskin-'+str(u)+'.jpgwhere v is the hero ID and u is the skin index (1‑12).
4. Download the images and save them into a folder named after each hero.
def main():
ii=0
for v in hero_number:
os.mkdir("/home/wajuejiprince/图片/WZRY/"+hero_name[ii])
os.chdir("/home/wajuejiprince/图片/WZRY/"+hero_name[ii])
ii+=1
for u in range(12):
onehero_links='http://game.gtimg.cn/images/yxzj/img201606/skin/hero-info/'+str(v)+'/'+str(v)+'-bigskin-'+str(u)+'.jpg'
im=requests.get(onehero_links)
if im.status_code==200:
iv=re.split('-',onehero_links)
open(iv[-1],'wb').write(im.content)Run main() to start the download.
League of Legends (英雄联盟) – US Server
Two methods are provided.
Method 1 – Direct URL Extraction
Fetch the champion list JSON, then use a regular expression to extract image URLs from each champion’s page.
#导入模块
import requests
import re
from bs4 import BeautifulSoup
url='http://ddragon.leagueoflegends.com/cdn/6.24.1/data/en_US/champion.json'
def get_hero_name(url):
head={'User-Agent':'Mozilla/5.0 ...'}
html=requests.get(url,headers=head)
hero_name=html.json()['data'].keys()
return [name.lower() for name in hero_name]
def get_onehero_img(name):
url2='http://gameinfo.na.leagueoflegends.com/en/game-info/champions/'+name+'/'
head={'User-Agent':'你自己的headers'}
html=requests.get(url2,headers=head)
soup=BeautifulSoup(html.text)
hero_img=soup.findAll('img')
reg=re.compile(r'"http://ddragon.leagueoflegends.com/cdn/img/.*?.jpg"',re.S)
return re.findall(reg,str(hero_img))Download each returned URL and save the files.
Method 2 – Simulated URL Pattern
Construct image URLs using the known pattern:
http://ddragon.leagueoflegends.com/cdn/img/champion/splash/{champion}_{index}.jpgIterate index from 0 to 19 (or higher) for each champion name obtained from the JSON.
for fn in list_of_nameMax:
os.mkdir("/home/.../LOL2/"+fn)
os.chdir("/home/.../LOL2/"+fn)
for v in range(20):
onehero_links='http://ddragon.leagueoflegends.com/cdn/img/champion/splash/'+fn+'_'+str(v)+'.jpg'
im=requests.get(onehero_links)
if im.status_code==200:
iv=onehero_links.split('/')
open(iv[-1],'wb').write(im.content)Smite (神之浩劫)
Fetch the list of god pages, extract background‑image URLs with a regex, and download them.
import requests, re, os
url='https://www.smitegame.com/gods/'
head={'User-Agent':'你的head'}
html=requests.get(url,headers=head)
reg=re.compile(r'href="(.*?)"\s+<img')
hero_url=re.findall(reg,html.text)
def one_hero_picture(ul):
html_hero=requests.get(ul,headers=head)
if html_hero.status_code==200:
reg2=re.compile(r'"background-image:url((.*?))"',re.S)
items2=re.findall(reg2,html_hero.text)
del items2[0]
return items2Iterate over each god URL, create a folder named after the god, and save all extracted images.
def main():
ii=0
for v in hero_url:
os.mkdir("/home/.../Smite/"+hero_name[ii])
os.chdir("/home/.../Smite/"+hero_name[ii])
ii+=1
one_hero=one_hero_picture(v)
for u in one_hero:
im=requests.get(u)
if im.status_code==200:
iv=u.split('/')
open(iv[-1],'wb').write(im.content)Run main() to download all Smite god skins.
Disclaimer
This crawler is intended solely for personal learning and entertainment; it must not be used for commercial purposes or any illegal activity.
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.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
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.
