利用Python下载王者荣耀的全部英雄高清海报【普通皮肤海报】

本文介绍如何使用Python和BeautifulSoup库自动化下载王者荣耀英雄海报,包括库的安装、代码编写以及下载过程的实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、前言

前几天,有人让我帮他下载王者荣耀英雄海报,便想着利用Python写个程序,要不然一个个下载太麻烦,也不是咱的作风

二、库安装

pip install beautifulsoup4
pip install lxml

三、编辑代码

import requests, re
from bs4 import BeautifulSoup

url = "https://pvp.qq.com/web201605/herolist.shtml"

headers = {
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36 Edg/115.0.1901.203"}

html = requests.request("get", url=url, headers=headers).text
soup = BeautifulSoup(html, "lxml")
list = []
for i in soup.find_all(attrs={"class": "herolist clearfix"}):
    for o in i.find_all("a"):
        list.append(f"https://pvp.qq.com/web201605/" + o.get("href"))

count = 1
for ix in list:
    htm = requests.get(url=ix, headers=headers)
    htm.encoding = "GBK"
    soup1 = BeautifulSoup(htm.text, "lxml")

    for z in soup1.find_all(attrs={"class": "zk-con1"}):
        name = soup1.find(attrs={"class": "cover-name"}).get_text()
        # print(z)
        ZG = z.get("style")
        img_urls = re.search("//.*?.jpg", str(ZG))
        imgs = f"http:" + img_urls.group()
        pic = requests.get(imgs).content
        with open(f"{name}.jpg", "wb") as f:
            f.write(pic)
        print(f"正在下载 === {name} == 英雄图片,这是第{count}张图片")
        count += 1
print("图片下载完毕!")

四、效果

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值