吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 4002|回复: 24
收起左侧

[Python 转载] python 下载壁纸

  [复制链接]
ZFX520 发表于 2021-8-21 20:47
本程序开发与@zfb 共同完成!
有时候不想在再手机上找壁纸,找了半天也找不到自己喜欢的,加载速度还比较慢。
索性就写了一个脚本,直接一直爬壁纸,你看几张壁纸的时间就能下载几十张壁纸,速度之快。
废话不多说直接附上源代码。

注:本程序执行会在桌面创建一个img的文件夹


[Python] 纯文本查看 复制代码
import requests, json, sys, time, os

url_template = "http://service.picasso.adesk.com:80/v1/vertical/{}vertical?{}limit=16&skip={}&adult=false&first=1&url=http%3A%2F%2Fservice.picasso.adesk.com%2Fv1%2Fvertical%2F{}vertical&order={}"

order='new'
skip = [0 for x in range(17)]
med_url = []
category_dict = {
    '1':["推荐", '','disorder=true&',skip[0],'','hot'],
    '2':["最新", '','',skip[0],'',order],
    '3':["美女", 'category/4e4d610cdf714d2966000000/','',skip[0],'category%2F4e4d610cdf714d2966000000%2F',order],
    '4':["动漫", 'category/4e4d610cdf714d2966000003/','',skip[0],'category%2F4e4d610cdf714d2966000003%2F',order],
    '5':["风景", 'category/4e4d610cdf714d2966000002/','',skip[0],'category%2F4e4d610cdf714d2966000002%2F',order],
    '6':["游戏", 'category/4e4d610cdf714d2966000007/','',skip[0],'category%2F4e4d610cdf714d2966000007%2F',order],
    '7':["文字", 'category/5109e04e48d5b9364ae9ac45/','',skip[0],'category%2F5109e04e48d5b9364ae9ac45%2F',order],
    '8':["视觉", 'category/4fb479f75ba1c65561000027/','',skip[0],'category%2F4fb479f75ba1c65561000027%2F',order],
    '9':["情感", 'category/4ef0a35c0569795756000000/','',skip[0],'category%2F4ef0a35c0569795756000000%2F',order],
    '10':["设计", 'category/4fb47a195ba1c60ca5000222/','',skip[0],'category%2F4fb47a195ba1c60ca5000222%2F',order],
    '11':["明星", 'category/5109e05248d5b9368bb559dc/','',skip[0],'category%2F5109e05248d5b9368bb559dc%2F',order],
    '12':["物语", 'category/4fb47a465ba1c65561000028/','',skip[0],'category%2F4fb47a465ba1c65561000028%2F',order],
    '13':["男人", 'category/4e4d610cdf714d2966000006/','',skip[0],'category%2F4e4d610cdf714d2966000006%2F',order],
    '14':["机械", 'category/4e4d610cdf714d2966000005/','',skip[0],'category%2F4e4d610cdf714d2966000005%2F',order],
    '15':["城市", 'category/4fb47a305ba1c60ca5000223/','',skip[0],'category%2F4fb47a305ba1c60ca5000223%2F',order],
    '16':["动物", 'category/4e4d610cdf714d2966000001/','',skip[0],'category%2F4e4d610cdf714d2966000001%2F',order],
    '17':["影视", 'category/4e58c2570569791a19000000/','',skip[0],'category%2F4e58c2570569791a19000000%2F',order]
}

def xh(url, file_name):
    headers = {
        'User-Agent': 'Mozilla/5.0 (X11; Linux armv7l) AppleWebKit/537.36 (KHTML, like Gecko) Raspbian Chromium/74.0.3729.157 Chrome/74.0.3729.157 Safari/537.36'
    }
    qq = requests.get(url, headers=headers).text
    qq1 = json.loads(qq)
    qq2 = qq1.get("res").get("vertical")
    q = []
    str_fmt = '{}图片-{}.jpg'
    if not os.path.exists('C:\\Users\\zfx\\Desktop\\img'):
        os.makedirs('C:\\Users\\zfx\\Desktop\\img\\')
    for a in qq2:
        q.append(a.get("img"))
    for u in q:
        print(u)
        i = time.time()
        fn = str_fmt.format(file_name, i)
        try:
            picture = requests.get(u).content
            with open('C:\\Users\\zfx\\Desktop\\img\\' + fn, 'wb')as file:
                file.write(picture)
        except Exception as e:
            print('错误:',e)
        else:
            print("下载成功~~",fn)


if __name__ == '__main__':
    display= ''
    for i in range(1,18):
        display = display + '{}={},'.format(str(i), category_dict[str(i)][0])
    display = display[:-1]
    text = input(display+"\n请输入命令:")
    index = 0
    while True:
        if text == 'q':
            sys.exit('您已正常退出!')
        if text == 'm':
            text = input(display+"\n请输入命令:")
            continue
        elif text == '':
            pass
        elif text in list(category_dict.keys()):
            index = text
        else:
            print("错误!!!")
        item = category_dict[index]
        url = url_template.format(item[1], item[2], item[3], item[4], item[5])
        xh(url, item[0])
        item[3] = item[3]+int(16)
        category_dict[index] = item
        text = input('“q”键退出,Enter继续执行,“m”键显示目录\n请输入命令:')



感谢大家的阅读

免费评分

参与人数 5吾爱币 +5 热心值 +5 收起 理由
kafei000 + 1 + 1 我很赞同!
zfb + 1 + 1 谢谢@Thanks!
qianqiong2020 + 1 + 1 热心回复!
Lyine + 1 + 1 谢谢@Thanks!
vaba + 1 + 1 沃瑞古德

查看全部评分

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

uvwxyz 发表于 2021-8-22 11:51

修复桌面创建文件夹错误的问题

[Python] 纯文本查看 复制代码
import requests
import json
import sys
import time
import os

url_template = "http://service.picasso.adesk.com:80/v1/vertical/{}vertical?{}limit=16&skip={}&adult=false&first=1&url=http%3A%2F%2Fservice.picasso.adesk.com%2Fv1%2Fvertical%2F{}vertical&order={}"

order = 'new'
skip = [0 for x in range(17)]
med_url = []
category_dict = {
    '1': ["推荐", '', 'disorder=true&', skip[0], '', 'hot'],
    '2': ["最新", '', '', skip[0], '', order],
    '3': ["美女", 'category/4e4d610cdf714d2966000000/', '', skip[0], 'category%2F4e4d610cdf714d2966000000%2F', order],
    '4': ["动漫", 'category/4e4d610cdf714d2966000003/', '', skip[0], 'category%2F4e4d610cdf714d2966000003%2F', order],
    '5': ["风景", 'category/4e4d610cdf714d2966000002/', '', skip[0], 'category%2F4e4d610cdf714d2966000002%2F', order],
    '6': ["游戏", 'category/4e4d610cdf714d2966000007/', '', skip[0], 'category%2F4e4d610cdf714d2966000007%2F', order],
    '7': ["文字", 'category/5109e04e48d5b9364ae9ac45/', '', skip[0], 'category%2F5109e04e48d5b9364ae9ac45%2F', order],
    '8': ["视觉", 'category/4fb479f75ba1c65561000027/', '', skip[0], 'category%2F4fb479f75ba1c65561000027%2F', order],
    '9': ["情感", 'category/4ef0a35c0569795756000000/', '', skip[0], 'category%2F4ef0a35c0569795756000000%2F', order],
    '10': ["设计", 'category/4fb47a195ba1c60ca5000222/', '', skip[0], 'category%2F4fb47a195ba1c60ca5000222%2F', order],
    '11': ["明星", 'category/5109e05248d5b9368bb559dc/', '', skip[0], 'category%2F5109e05248d5b9368bb559dc%2F', order],
    '12': ["物语", 'category/4fb47a465ba1c65561000028/', '', skip[0], 'category%2F4fb47a465ba1c65561000028%2F', order],
    '13': ["男人", 'category/4e4d610cdf714d2966000006/', '', skip[0], 'category%2F4e4d610cdf714d2966000006%2F', order],
    '14': ["机械", 'category/4e4d610cdf714d2966000005/', '', skip[0], 'category%2F4e4d610cdf714d2966000005%2F', order],
    '15': ["城市", 'category/4fb47a305ba1c60ca5000223/', '', skip[0], 'category%2F4fb47a305ba1c60ca5000223%2F', order],
    '16': ["动物", 'category/4e4d610cdf714d2966000001/', '', skip[0], 'category%2F4e4d610cdf714d2966000001%2F', order],
    '17': ["影视", 'category/4e58c2570569791a19000000/', '', skip[0], 'category%2F4e58c2570569791a19000000%2F', order]
}


def xh(url, file_name):
    headers = {
        'User-Agent': 'Mozilla/5.0 (X11; Linux armv7l) AppleWebKit/537.36 (KHTML, like Gecko) Raspbian Chromium/74.0.3729.157 Chrome/74.0.3729.157 Safari/537.36'
    }
    qq = requests.get(url, headers=headers).text
    qq1 = json.loads(qq)
    qq2 = qq1.get("res").get("vertical")

    str_fmt = '{}图片-{}.jpg'
    desk = os.path.join(os.path.expanduser("~"), "Desktop", "imgs")
    if not os.path.exists(desk):
        os.makedirs(desk)
    for u in [a.get("img") for a in qq2]:
        print(u)
        i = time.time()
        fn = str_fmt.format(file_name, i)
        try:
            picture = requests.get(u).content
            with open(os.path.join(desk, fn), 'wb')as file:
                file.write(picture)
        except Exception as e:
            print('错误:', e)
        else:
            print("下载成功~~", fn)


if __name__ == '__main__':
    display = ''
    for i in range(1, 18):
        display = display + '{}={},'.format(str(i), category_dict[str(i)][0])
    display = display[:-1]
    text = input(display+"\n请输入命令:")
    index = 0
    while True:
        if text == 'q':
            sys.exit('您已正常退出!')
        if text == 'm':
            text = input(display+"\n请输入命令:")
            continue
        elif text == '':
            pass
        elif text in list(category_dict.keys()):
            index = text
        else:
            print("错误!!!")
        item = category_dict[index]
        url = url_template.format(item[1], item[2], item[3], item[4], item[5])
        xh(url, item[0])
        item[3] = item[3]+int(16)
        category_dict[index] = item
        text = input('“q”键退出,Enter继续执行,“m”键显示目录\n请输入命令:')
 楼主| ZFX520 发表于 2021-8-23 11:45
kafei000 发表于 2021-8-22 19:17
感谢楼主,这个是接口,可以分享下网站吗,我想学习学习

这是一个壁纸软件的接口,没有在软件中发现有官网的链接或者是网页版的,我是通过抓包获取的,软件不太方便分享
白泽1994 发表于 2021-8-21 22:56
kuangshen133 发表于 2021-8-21 23:13
感谢,可以下高清壁纸了
tbloy 发表于 2021-8-22 00:22
支持一下原创,不错。
MXGT 发表于 2021-8-22 00:41
nice,感谢分享。
李佑辰 发表于 2021-8-22 01:56
很不错哦 支持分享!!
cogi 发表于 2021-8-22 07:07
支持一下原创,不错。
龍謹 发表于 2021-8-22 07:59
谢谢分享,学习PY的来了。
xzzhjian 发表于 2021-8-22 08:10
正需要这个好资源。谢谢分享。
laph 发表于 2021-8-22 08:24
谢谢大佬分享。。试下
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

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

GMT+8, 2024-11-25 08:30

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

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