本帖最后由 天轩科技 于 2023-8-19 03:00 编辑
主要用来练习锻炼编码能力,有一些语法可能写的不是很好,请帮忙指出!谢谢~
[Python] 纯文本查看 复制代码 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).content
soup1 = BeautifulSoup(htm, "lxml")
for img_pf in soup1.find_all(attrs={"class":"pic-pf-list pic-pf-list3"}):
img_pf_name = img_pf.get('data-imgname').split('|')
temp_list = []
for index,pf_no in enumerate(img_pf_name):
temp_list.append([index+1,pf_no])
for z in soup1.find_all(attrs={"class": "zk-con1"}):
Get_style = z.get('style')
img_url = re.search(r"//.*-",str(Get_style)).group()
for io in temp_list:
hero_name = soup1.find(attrs={"class": "cover-name"}).get_text()
style_name = re.search(r'[\u4e00-\u9fa5]+',str(io[1])).group()
style_index = (io[0])
hero_url = f'https:' + str(img_url) + str(style_index) +".jpg"
pic = requests.get(hero_url).content
with open(f"{hero_name}-{style_name}.jpg", "wb") as f:
f.write(pic)
print(f"正在下载 === 英雄 :【{hero_name}】 的 【{style_name} 】皮肤图片 ==,这是下载的第{count}张图片。")
count += 1
print(f"图片下载完毕!总共下载图片为{count}张。")
图片量有点多,上传到123云盘。
下载地址:https://www.123pan.com/s/JQNuVv-KxIw3.html |