吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 1879|回复: 37
收起左侧

[Python 原创] 某珍宝馆图片下载,自动合并

  [复制链接]
hebeijianke 发表于 2024-7-26 21:14
本帖最后由 hebeijianke 于 2024-7-26 21:29 编辑

看到求助帖有人需要 @幸甚至哉

代码比较简单,只能下载较小的图片,图像的宽度和高度小于65500像素,好像python的几个图像处理模块都对拼接大图有限制,
注意:只能下载【书画】和【拾英】板块免费的,需要会员的不能下载,单线程下载,有点慢。
希望大佬优化一下代码吧。
[Python] 纯文本查看 复制代码
import requests
from PIL import Image
from io import BytesIO
import os


def main(url):
    headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/114.0',
               'Origin': 'https://g2.ltfc.net'}
    tourToken = requests.post("https://api.quanku.art/cag2.TouristService/getAccessToken", headers=headers).json()['token']
    # url = 'https://g2.ltfc.net/view/SUHA/657e79d2ace3dd0d7a7a74b4'
    id1 = url.split('/')[-1]
    T = url.split('/')[-2].lower().title()
    u1 = f'https://api.quanku.art/cag2.{T}Service/get'
    u2 = 'https://api.quanku.art/cag2.HDPicService/get'
    u3 = 'https://api.quanku.art/cag2.HDPicService/getHDPicOfColl'
    payload1 = {"Id": id1, "context": {"tourToken": tourToken, "appKey": "CAGWEB", "appSec": "ZETYK0B8KTQB41KYWA2"}}
    res1 = requests.post(u1, headers=headers, json=payload1).json()
    id2 = ''
    src = ''
    title = ''
    if 'Suha' == T:
        title = res1['name']
        id2 = res1['hdp']['id']
        src = res1['hdp']['src']
    elif 'Shiy' == T:
        title = res1['title']
        id2 = res1['hdp']['id']
        src = res1['hdp']['src']
    payload2 = {"Id": id2, "context": {"tourToken": tourToken, "appKey": "CAGWEB", "appSec": "ZETYK0B8KTQB41KYWA2"}}
    if src == 'PIC':
        res = requests.post(u2, headers=headers, json=payload2).json()
        resourceId = res['resourceId']
        name = res['name']
        maxlevel = res['maxlevel']
        size = res['size']
        h = size['height']
        w = size['width']
        download_and_paste_image(w, h, title, name, resourceId, maxlevel)
    else:
        res = requests.post(u3, headers=headers, json=payload2).json()
        for i in res['data']:
            resourceId = i['resourceId']
            name = i['name']
            maxlevel = i['maxlevel']
            size = i['size']
            h = size['height']
            w = size['width']
            download_and_paste_image(w, h, title, name, resourceId, maxlevel)


def download_and_paste_image(w, h, title, name, id, maxlevel):
    if title == name:
        t_m = name
    else:
        t_m = title + '_' + name
    new_img = Image.new('RGB', (w, h))
    for i in range(0, w // 512 + 1):
        for j in range(0, h // 512 + 1):
            p_url = 'https://cags.ltfc.net/cagstore/{}/{}/{}_{}.jpg'.format(id, maxlevel, i, j)
            response = requests.get(p_url)
            response.raise_for_status()  # 如果请求失败,则抛出HTTPError异常
            # with open(f'{i}_{j}.jpg', 'wb') as f:  # 取消注释下载切割后的图片片段到本地
            #     f.write(response.content)
            img = Image.open(BytesIO(response.content))
            new_img.paste(img, (512 * i, 512 * j))
    new_img.save(t_m + '.jpg')
    new_img.close()
    del new_img


if __name__ == "__main__":
    url = input('输入网址:')
    main(url)

免费评分

参与人数 6吾爱币 +13 热心值 +4 收起 理由
deathknight + 1 + 1 谢谢@Thanks!
苏紫方璇 + 7 + 1 欢迎分析讨论交流,吾爱破解论坛有你更精彩!
aholdmyhand + 1 我很赞同!
枫叶荻花 + 2 + 1 我很赞同!
gzz1071453752 + 1 + 1 用心讨论,共获提升!
chuiwangssa + 1 我很赞同!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

nan5201314 发表于 2024-7-26 21:22
刚好需要,点了
yesyunxin 发表于 2024-7-26 21:34
a30914 发表于 2024-7-26 21:52
hjm350427 发表于 2024-7-26 21:54
谢谢分享,刚好学习一下。
ayx2012 发表于 2024-7-26 22:10
谢谢分享 楼主辛苦
777QWQ777 发表于 2024-7-26 22:24
学习一下
yawee 发表于 2024-7-26 22:46
刚需,感谢分享
takajihan 发表于 2024-7-26 22:49
谢谢分享,刚好学习一下
sq0228 发表于 2024-7-26 22:51
多谢分享
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-9-8 09:33

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表