Python通过requests模块实现抓取王者荣耀全套皮肤
作者:小雁子学Python 发布时间:2022-04-06 05:47:12
标签:Python,抓取王者荣耀皮肤,requests
前言
今天带大家爬取王者荣耀全套皮肤,废话不多说,直接开始~
开发工具
Python版本: 3.6.4
相关模块:
requests模块;
urllib模块;
以及一些Python自带的模块。
环境搭建
安装Python并添加到环境变量,pip安装需要的相关模块即可。
思路分析
1、打开官方王者荣耀壁纸网站
网站地址:https://pvp.qq.com/web201605/wallpaper.shtml
2、快捷键F12,调出控制台进行抓包
3、找到正确的链接并分析
4、查看返回数据格式
5、解析url链接
6、查看url内容是否是所需图片,发现其实是缩略图
7、那就去分析网站,随便点开一张壁纸,查看指定格式的链接
8、找到目标地址
9、分析目标链接和缩略图的链接区别
缩略图:http://shp.qpic.cn/ishow/2735090714/1599460171_84828260_8311_sProdImgNo_6.jpg/200
目标图:http://shp.qpic.cn/ishow/2735090714/1599460171_84828260_8311_sProdImgNo_6.jpg/0
可以知道,将指定格式的缩略图地址后面200替换成0就是目标真实图片
代码实现
import os, time, requests, json, re
from retrying import retry
from urllib import parse
class HonorOfKings:
'''
This is a main Class, the file contains all documents.
One document contains paragraphs that have several sentences
It loads the original file and converts the original file to new content
Then the new content will be saved by this class
'''
def __init__(self, save_path='./heros'):
self.save_path = save_path
self.time = str(time.time()).split('.')
self.url = 'https://apps.game.qq.com/cgi-bin/ams/module/ishow/V1.0/query/workList_inc.cgi?activityId=2735&sVerifyCode=ABCD&sDataType=JSON&iListNum=20&totalpage=0&page={}&iOrder=0&iSortNumClose=1&iAMSActivityId=51991&_everyRead=true&iTypeId=2&iFlowId=267733&iActId=2735&iModuleId=2735&_=%s' % self.time[0]
def hello(self):
'''
This is a welcome speech
:return: self
'''
print("*" * 50)
print(' ' * 18 + '王者荣耀壁纸下载')
print(' ' * 5 + '作者: Felix Date: 2020-05-20 13:14')
print("*" * 50)
return self
def run(self):
'''
The program entry
'''
print('↓' * 20 + ' 格式选择: ' + '↓' * 20)
print('1.缩略图 2.1024x768 3.1280x720 4.1280x1024 5.1440x900 6.1920x1080 7.1920x1200 8.1920x1440')
size = input('请输入您想下载的格式序号,默认6:')
size = size if size and int(size) in [1,2,3,4,5,6,7,8] else 6
print('---下载开始...')
page = 0
offset = 0
total_response = self.request(self.url.format(page)).text
total_res = json.loads(total_response)
total_page = --int(total_res['iTotalPages'])
print('---总共 {} 页...' . format(total_page))
while True:
if offset > total_page:
break
url = self.url.format(offset)
response = self.request(url).text
result = json.loads(response)
now = 0
for item in result["List"]:
now += 1
hero_name = parse.unquote(item['sProdName']).split('-')[0]
hero_name = re.sub(r'[【】:.<>|·@#$%^&() ]', '', hero_name)
print('---正在下载第 {} 页 {} 英雄 进度{}/{}...' . format(offset, hero_name, now, len(result["List"])))
hero_url = parse.unquote(item['sProdImgNo_{}'.format(str(size))])
save_path = self.save_path + '/' + hero_name
save_name = save_path + '/' + hero_url.split('/')[-2]
if not os.path.exists(save_path):
os.makedirs(save_path)
if not os.path.exists(save_name):
with open(save_name, 'wb') as f:
response_content = self.request(hero_url.replace("/200", "/0")).content
f.write(response_content)
offset += 1
print('---下载完成...')
@retry(stop_max_attempt_number=3)
def request(self, url):
'''
Send a request
:param url: the url of request
:param timeout: the time of request
:return: the result of request
'''
response = requests.get(url, timeout=10)
assert response.status_code == 200
return response
if __name__ == "__main__":
HonorOfKings().hello().run()
本期完整源代码可以私信获取
代码运行结果
来源:https://blog.csdn.net/weixin_43649691/article/details/120992429
0
投稿
猜你喜欢
- 本程序是利用3.x的Firefox浏览器可以读取本地文件的特性,实现通过xmlHttPRequest上传大文件功能,并在可以上传过程中动态显
- 本文实例为大家分享了python+pygame实现坦克大战的具体代码,供大家参考,具体内容如下一、首先导入pygame库二、源码分享#cod
- 一、ts文件的由来ts文件,ts即"Transport Stream"的缩写,特点就是要求从视频流的任一片段开始都是可以
- 在python中读取csv文件时,一般操作如下:import pandas as pdpd.read_csv(filename)该读文件方式
- 一 概念1. 原理2. 好处不同项目可能用到的环境不同,运用虚拟环境能将不同环境分隔开二 virtualenvvirtual 虚拟的1. 安
- 使用ENUM代替字符串类型有时候, 可以通过使用ENUM来代理常规的字符串类型。一个ENUM列能够存储65535个不同的字符串值,MySQL
- 如下所示:# -*-coding:utf-8-*-from pandas import DataFrameimport pandas as
- 前言使用matplotlib生成gif动画的方法有很多,一般常规使用matplotlib的animation模块的FuncAnimation
- 在神经网络入门回顾(感知器、多层感知器)中整理了关于感知器和多层感知器的理论,这里实现关于与门、与非门、或门、异或门的代码,以便对感知器有更
- 一、读写文件在 Python 中,我们可以使用 open() 函数打开文件,with 语句可以自动关闭文件。读取文件内容:with open
- Python基础环境搭建CENTOS 6.X 系列默认安装的 Python 2.6 ,目前开发中主要是使用 Python 2.7 ,这两个版
- CSS制作滑动折叠的文字效果,可以用于二级导航菜单的制作,不错的下拉菜单。<!DOCTYPE html PUBLIC "-/
- 一、概念介绍Thread 是threading模块中最重要的类之一,可以使用它来创建线程。有两种方式来创建线程:一种是通过继承Thread类
- 大概在Python2.7.xx以前,安装Python时环境变量是需要自己设的,所以自己做了一个批处理文件.bat来设置环境变量Path,通过
- 一、h5py模块介绍本文只是简单的对h5py库的基本创建文件,数据集和读取数据的方式进行介绍!如果读者需要进一步详细的学习h5py的更多知识
- win32com和微软的word接口文档有什么关系先回答一个网友私信问题: win32com和微软的word接口文档有什么关系win32co
- Oracle是目前应用最广泛的数据库系统。一个完整的数据库系统包括系统硬件、操作系统、网络层、DBMS(数据库管理系统)、应用程序与数据,各
- 文字链接可以说是网页中最常见的页面元素了,默认的文字链接样式都是带下划线的效果,这种一陈不变的外观可能使很多朋友都想改变它,以使之符合页面的
- 用的pytorch来训练deeplabv3+在做deeplabv3+的过程中,我的训练图片是8位的,如下图:8位的:24位的:这样虽然在训练
- 代码如下:'===================================== '转换内容,防止意外 '==