Python | GGAC插画(尊重版权 仅供学习)

# -*- coding:utf-8 -*-
from pyquery import PyQuery
import requests
import os


def get_name_id(count):
    url = 'https://www.ggac.com/api/v2/work'
    param = {
        'right_conditions': "hot",
        'tag_subtype': "场景概念",
        'current_page': "1",
        'page_size': "{}".format(count),
    }
    json = requests.post(url, data=param).json()['data']
    total = json['works_count']
    if total < int(count):
        print('作品数一共才{}件,您输入的{}超过{},请重新输入!'.format(total, count, total))
        exit()
    if int(count) > 200:
        print("所需下载作品件数较大,请耐心等待加载...")
    name_id = []
    for one in json['works']:
        name_id.append((one['title'], one['id']))
    return name_id


def get_image_save(image_info: list):
    url = 'https://www.ggac.com/api/v2/work/attachment'
    count = 1
    for img_name, img_id in image_info:
        print(count, img_name, sep=' ', end='  ')
        param = {
            'wid': "{}".format(img_id),
            'type': "image",
            'current_page': "1",
            'page_size': "20"
        }
        json = requests.post(url, data=param).json()['data']['work_images']
        image_url = []
        for one in json:
            image_url.append(one['url'])
        for index, img in enumerate(image_url):
            if len(image_url) == 1:
                with open(img_name + '.jpg', 'wb') as f:
                    f.write(requests.get(img).content)
            else:
                with open(img_name + '_{}.jpg'.format(index + 1), 'wb') as f:
                    f.write(requests.get(img).content)
            print(index + 1, end='  ')
        count += 1
        print("下载完成...")


if __name__ == '__main__':
    path = os.getcwd() + "\GGAC-CG艺术画"
    if not os.path.exists(path):
        os.mkdir(path)
    os.chdir(path)
    num = input("请输入下载の作品数:")
    if num.isdigit() and int(num) > 0:
        al = get_name_id(num)
        get_image_save(al)
    else:
        print("请输入一个正整数!!!")
posted @   槑孒  阅读(134)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
点击右上角即可分享
微信分享提示