王者荣耀皮肤图片爬虫
本帖最后由 天空宫阙 于 2019-12-16 20:16 编辑找到了这个接口,只要改page参数就可以了page= 0到19有内容
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=0&iOrder=0&iSortNumClose=1&jsoncallback=jQuery17108079906974233315_1576410038567&iAMSActivityId=51991&_everyRead=true&iTypeId=2&iFlowId=267733&iActId=2735&iModuleId=2735&_=1576410754875
可能有多余的参数懒得调试就这样一起提交算了
完整的代码
import requests
import re
import json
import urllib.parse
from tqdm import tqdm
import time
headers ={
'user-agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.79 Safari/537.36'
}
def get_picSrc(page):
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&jsoncallback=jQuery17108079906974233315_1576410038567&iAMSActivityId=51991&_everyRead=true&iTypeId=2&iFlowId=267733&iActId=2735&iModuleId=2735&_=1576410754875'.format(str(page))
response = requests.get(url,headers=headers)
if response.status_code ==200:
# print(response.text)
temp = re.search('jQuery\d+_\d+\((.*?)\)',response.text,re.S)
if temp:
data = json.loads(temp.group(1))
data_list = data['List']
for item in data_list:
sProdName = urllib.parse.unquote(item['sProdName'])
sProdImgNo_8 = urllib.parse.unquote(item['sProdImgNo_8'])
pic_src = sProdImgNo_8[:-3]+'0'
pic_info ={
'sProdName':sProdName,
'pic_src':pic_src
}
yield pic_info
def downloadFILE(url,name):
headers={
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36'
}
resp = requests.get(url=url,stream=True,headers=headers)
content_size = int(int(resp.headers['Content-Length'])/1024)
with open(name, "wb") as f:
print("Pkg total size is:",content_size,'k,start...')
for data in tqdm(iterable=resp.iter_content(1024),total=content_size,unit='k',desc=name):
f.write(data)
print(name , "download finished!")
if __name__ == "__main__":
for page in range(0,20):
print(' page:',page)
pic_infos = get_picSrc(page)
for pic_info in pic_infos:
print(pic_info)
try:
downloadFILE(pic_info['pic_src'],pic_info['sProdName']+'.jpg')
except:
continue
time.sleep(3)
效果如图
一共爬了390张,好像漏了5张,懒得做异常处理就这样吧。
代码中sProdImgNo_8的部分改成sProdImgNo_6就可以下载1920*1080格式的了,1到8分别是不同尺寸的,但左上还是有王者荣耀的水印,没有水印的是爬取英雄资料的背景图片是1920*822格式了,百度一下一大堆人已经写过了,就不写了。
下载完的文件有点大就不放了,放一个下载工具的链接,有py和封装成的exe,双击即可下载,不愧是腾讯的服务器,下载的真快。
py和封装成的exe:https://www.lanzouj.com/i81e7hc
记得在文件夹中运行,否则被图片铺满桌面不关我的事情。
本帖最后由 badyun 于 2019-12-15 22:26 编辑
看了下楼主的代码,用js复写了一遍
const superagent = require('superagent');
const fs = require('fs');
const downloadFile = async (url, filepath) => {
const mypath = filepath
const writer = fs.createWriteStream(mypath);
superagent(url).pipe(writer)
return new Promise((resolve, reject) => {
writer.on("finish", resolve);
writer.on("error", reject);
});
};
(async () => {
for (let i = 0; i <= 5; i++) {
// 每页96个时,最多5页
let s = await superagent.get('https://apps.game.qq.com/cgi-bin/ams/module/ishow/V1.0/query/workList_inc.cgi')
.query({
sDataType: 'JSON',
iListNum: 96,
page: i,
iActId: 2735
})
let result = JSON.parse(s.text).List
for (let index in result) {
let ele = result
let picInfo = {
sProdName: decodeURIComponent(ele.sProdName),
picSrc: decodeURIComponent(ele.sProdImgNo_8).replace('/200', '/0')
}
await downloadFile(picInfo.picSrc, './wangzhe/' + picInfo.sProdName + '.jpg')
}
}
})() ��չ��� ������ 2019-12-15 22:14
����👍������ֻ��python�ģ���Ϊ�ö����ݶ���js��Ⱦ��Ϊ����������Ҳѧ��һ��JavaScript�������� ...
哈哈,混淆的我看着也难受 牛皮!!!优秀, 能不能爬无水印的呀?? 谢谢,学习了,很多心小东西,,,, 这个干嘛用? zhunxing358 发表于 2019-12-15 21:47
这个干嘛用?
爬着玩,抓包练习 迦南圣经 发表于 2019-12-15 21:38
能不能爬无水印的呀??
应该是可以的,没注意水印,就看了下图片很高清就下载了,有时间再改 天空宫阙 发表于 2019-12-15 21:54
应该是可以的,没注意水印,就看了下图片很高清就下载了,有时间再改
可以,坐等大佬修整2.0