Python爬取 | 王者荣耀英雄皮肤海报
这里只展示代码,具体介绍请点击下方链接。
Python爬取 | 王者荣耀英雄皮肤海报
import requests
import re
import os
import time
import winreg
count = 0 # 计数用
# 获取第一次页面所以英雄的id以及名字
def first_url(url):
response = requests.get(url)
response.encoding = 'gbk'
response = response.text
id_name = re.findall('<li><a href=.*?/(\d{3}).*?alt=.*?>(.*?)</a></li>', response, re.S)
return id_name
# 获取英雄皮肤昵称以及获取皮肤数目
def second_url(url, name):
response = requests.get(url)
response.encoding = 'gbk'
response = response.text
# 第66行
# <ul class="pic-pf-list pic-pf-list3" data-imgname="月光之女&0|哥特玫瑰&1|绯红之刃&0|紫霞仙子&12|一生所爱&44|瓷语鉴心&1">
response = re.findall('<ul class=.*?data-imgname="(.*?)">', response)
response = response[0].split('|')
skin_names = []
for i in response:
names = re.sub('[^\u4e00-\u9fa5]', '', i) + ' ' + name
skin_names.append(names)
return skin_names
def download(url, skin_names, path):
num = len(skin_names) # 获取英雄皮肤数目,以控制循环次数
times = str(num) # 将皮肤个数字符化,用于文件名称显示皮肤个数
name = skin_names[0].split(' ')[-1] # 这里是获取英雄名字,如露娜,用于后面皮肤全称的拼接
path = path + '/' + name + ' ' + times + '张' # 皮肤存储路径
if not os.path.exists(path): # 如果路径不存在,则自动创建
os.mkdir(path)
for n in range(0, num): # 循环
skin_url = url + str(n + 1) + '.jpg' # 皮肤图片的链接
image_path = path + '/' + skin_names[n] + '.jpg' # 每张皮肤的命名
global count # 定义全局变量,用于统计皮肤下载张数
count = count + 1
print(f' 第{count}张 正在下载>>{name}<<的第{str(n + 1)}张皮肤,共{times}张')
with open(image_path, 'wb') as f: # 皮肤图片下载并保存
f.write(requests.get(skin_url).content)
time.sleep(0.3)
def get_desktop():
key = winreg.OpenKey(winreg.HKEY_CURRENT_USER,
r'Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders') # 利用系统的链表
zm = winreg.QueryValueEx(key, "Desktop")[0] # 获取的是Unicode类型数据
return str(zm) # Unicode转化为str并返回
def main():
path = f'{get_desktop()}\\王者荣耀角色皮肤图片'
print(path)
if not os.path.exists(path):
os.mkdir(path)
url = 'https://pvp.qq.com/web201605/herolist.shtml'
id_name = first_url(url)
# 拼接链接
for i in id_name:
hero_url = f'http://pvp.qq.com/web201605/herodetail/{i[0]}.shtml'
skin_names = second_url(hero_url, i[1]) # i[1]是英雄的名字,比如露娜,云中君等
skin_url = f'http://game.gtimg.cn/images/yxzj/img201606/skin/hero-info/{i[0]}/{i[0]}-bigskin-'
download(skin_url, skin_names, path)
if __name__ == '__main__':
main()
Python爬取 | 王者荣耀英雄皮肤海报的更多相关文章
- python 爬取王者荣耀英雄皮肤代码
import os, time, requests, json, re, sys from retrying import retry from urllib import parse "& ...
- 利用python爬取王者荣耀英雄皮肤图片
前两天看到同学用python爬下来LOL的皮肤图片,感觉挺有趣的,我也想试试,于是决定来爬一爬王者荣耀的英雄和皮肤图片. 首先,我们找到王者的官网http://pvp.qq.com/web201605 ...
- python学习--第二天 爬取王者荣耀英雄皮肤
今天目的是爬取所有英雄皮肤 在爬取所有之前,先完成一张皮肤的爬取 打开anacond调出编译器Jupyter Notebook 打开王者荣耀官网 下拉找到位于网页右边的英雄/皮肤 点击[+更多] 进入 ...
- Python 爬取 "王者荣耀.英雄壁纸" 过程中的矛和盾
1. 前言 学习爬虫,最好的方式就是自己编写爬虫程序. 爬取目标网站上的数据,理论上讲是简单的,无非就是分析页面中的资源链接.然后下载.最后保存. 但是在实施过程却会遇到一些阻碍. 很多网站为了阻止爬 ...
- 用Python爬取"王者农药"英雄皮肤
0.引言 作为一款现象级游戏,王者荣耀,想必大家都玩过或听过,游戏里中各式各样的英雄,每款皮肤都非常精美,用做电脑壁纸再合适不过了.本篇就来教大家如何使用Python来爬取这些精美的英雄皮肤. 1.环 ...
- 用Python爬取"王者农药"英雄皮肤 原
padding: 10px; border-bottom: 1px solid #d3d3d3; background-color: #2e8b57; } .second-menu-item { pa ...
- python爬取王者荣耀全英雄皮肤
import os import requests url = 'https://pvp.qq.com/web201605/js/herolist.json' herolist = requests. ...
- python爬虫---爬取王者荣耀全部皮肤图片
代码: import requests json_headers = { "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win ...
- python 爬取王者荣耀高清壁纸
代码地址如下:http://www.demodashi.com/demo/13104.html 一.前言 打过王者的童鞋一般都会喜欢里边设计出来的英雄吧,特别想把王者荣耀的英雄的高清图片当成电脑桌面 ...
随机推荐
- Go版本依赖--伪版本
目录 1.简介 2. 什么是伪版本 3. 伪版本风格 4. 如何获取伪版本 1.简介 在go.mod中通常使用语义化版本来标记依赖,比如v1.2.3.v0.1.5等.因为go.mod文件通常是go命令 ...
- 证明n个正数的算术平均数不小于它们的几何平均数
- centos7 wget安装jdk
2021-07-151. 环境介绍 操作系统:centos7 jdk版本:jdk1.8.0.211 2. 下载 进入 https://www.oracle.com/java/technologies/ ...
- 通过 layout 探索 kratos 运行原理
创建项目 首先需要安装好对应的依赖环境,以及工具: go 下载 protoc go install google.golang.org/protobuf/cmd/protoc-gen-go@lates ...
- openresty lua_ssl_trusted_certificate 问题
lua_ssl_trusted_certificate 语法: lua_ssl_trusted_certificate 默认: no 环境: http, server, location 指定一个 P ...
- 剑指 Offer 33. 二叉搜索树的后序遍历序列
剑指 Offer 33. 二叉搜索树的后序遍历序列 输入一个整数数组,判断该数组是不是某二叉搜索树的后序遍历结果.如果是则返回 true,否则返回 false.假设输入的数组的任意两个数字都互不相同. ...
- springmvc图片上传、json
springmvc的图片上传 1.导入相应的pom依赖 <dependency> <groupId>commons-fileupload</groupId> < ...
- Pytest 系列(28)- 参数化 parametrize + @allure.title() 动态生成标题
如果你还想从头学起Pytest,可以看看这个系列的文章哦! https://www.cnblogs.com/poloyy/category/1690628.html 前言 参数化 @pytest.ma ...
- VUE005. 在data中使用 / 改变data,或在data中调用method函数
使用三方UI库时经常会遇到在data中写入方法的场景,如Element-UI的级联选择器(动态加载part)需要在data中写入lazyLoad. 但后端总会给出意想不到的需求: 通过接口调取一串数据 ...
- python多继承简单方法
class people(object): #建创一个人类 def __init__(self,name,age): self.name = name self.age = age def eat(s ...