首先抓包,翻页可以看到数据储存在该包
可以看到随着页面变化,只有current在变化
而且载荷都没有加密,看来不用js逆向了
爬取代码
import os
import asyncio
import aiohttp
import json
headers = {
"accept": "application/json, text/plain, */*",
"accept-language": "zh-CN,zh;q=0.9,oc;q=0.8",
"cache-control": "no-cache",
"content-type": "application/json;charset=UTF-8",
"origin": "https://bz.zzzmh.cn",
"pragma": "no-cache",
"priority": "u=1, i",
"referer": "https://bz.zzzmh.cn/",
"sec-ch-ua": "\"Google Chrome\";v=\"131\", \"Chromium\";v=\"131\", \"Not_A Brand\";v=\"24\"",
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": "\"Windows\"",
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "same-site",
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36"
}
url = "https://api.zzzmh.cn/v2/bz/v3/getData"
# 确保downloads文件夹存在
downloads_folder = 'D:\\极简壁纸'
if not os.path.exists(downloads_folder):
os.makedirs(downloads_folder)
async def download_image(session, img_url, filename):
async with session.get(img_url, headers=headers) as response:
if response.status == 200:
with open(os.path.join(downloads_folder, filename), 'wb') as f:
f.write(await response.read())
print(filename + '下载成功')
else:
print(f"Failed to download {filename}: {response.status}")
async def main():
index = input("请输入你要下载的页数:")
async with aiohttp.ClientSession() as session:
for i in range(1, int(index) + 1):
data = {
"size": 24,
"current": i,
"sort": 0,
"category": 0,
"resolution": 0,
"color": 0,
"categoryId": 0,
"ratio": 0
}
data = json.dumps(data, separators=(',', ':'))
async with session.post(url, headers=headers, data=data) as response:
response_json = await response.json()
link = [item['i'] for item in response_json['data']['list']]
point = [item['t'] for item in response_json['data']['list']]
shix = 1
tasks = []
for item, po in zip(link, point):
if po == 1:
img_url = f'https://api.zzzmh.cn/v2/bz/v3/getUrl/{item}19'
elif po == 2:
img_url = f'https://api.zzzmh.cn/v2/bz/v3/getUrl/{item}29'
filename = f'{i}.{shix}.jpg'
tasks.append(download_image(session, img_url, filename))
shix += 1
await asyncio.gather(*tasks)
if __name__ == "__main__":
asyncio.run(main())