Python爬取王者荣耀英雄皮肤

import requests
import re
import json
import os

headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36"}

def get_pic(pic, path, num):
    with open(path + fr"\{num}.jpg","wb+") as f:
        f.write(pic)
    print(fr"Downloaded {num}!")

def get_hero(txt, num):
    name = re.findall("<h2 class=\"cover-name\">(\S*)</h2>", txt)[0]
    path = fr"E:\LH\无聊乱搞\二次元\王者皮肤\{name}"
    if not os.path.exists(path):
        os.makedirs(path)
    print(fr"找到{name}!")
    for i in range(1,11):
        pic_url = fr"https://game.gtimg.cn/images/yxzj/img201606/skin/hero-info/{num}/{num}-bigskin-{i}.jpg"
        res = requests.get(pic_url, headers = headers)
        if(res.status_code == 200):
            pic = res.content
            get_pic(pic, path, i)
        else:
            break

for i in range(100,1000):
    hero_url = fr"https://pvp.qq.com/web201605/herodetail/{i}.shtml"
    res = requests.get(hero_url, headers = headers)
    if(res.status_code == 200):
        res.encoding = res.apparent_encoding
        txt = res.text
        get_hero(txt, i)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值