Created
October 27, 2019 01:12
-
-
Save ookcode/6554a6085ef43741a4b2b13fc2ce63c7 to your computer and use it in GitHub Desktop.
爬王者荣耀全皮肤海报
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import re | |
import os | |
url = 'http://pvp.qq.com/web201605/js/herolist.json' | |
url_formatter = "http://game.gtimg.cn/images/yxzj/img201606/skin/hero-info/{}/{}-bigskin-{}.jpg" | |
headers = { | |
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36' | |
} | |
root_path = os.path.dirname(os.path.realpath(__file__)) | |
def main(): | |
html = requests.get(url, headers = headers) | |
html_json = html.json() | |
hero_names = list(map(lambda x:x['cname'], html_json)) | |
hero_numbers = list(map(lambda x:x['ename'], html_json)) | |
# print(hero_numbers) | |
# print(hero_names) | |
index = 0 | |
for hero_num in hero_numbers: | |
print("{} : {}".format(hero_num, hero_names[index])) | |
save_path = os.path.join(root_path, hero_names[index]) | |
os.mkdir(save_path) | |
os.chdir(save_path) | |
index = index + 1 | |
for skin_index in range(20): # can not get skin count, try 20 skin | |
img_link = url_formatter.format(hero_num, hero_num, skin_index) | |
req = requests.get(img_link) | |
if req.status_code == 200: | |
print(img_link, "download success") | |
img_name = "bigskin-{}.jpg".format(skin_index) | |
with open(img_name, 'wb') as file: | |
file.write(req.content) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment