python 下载壁纸
本程序开发与@zfb 共同完成!有时候不想在再手机上找壁纸,找了半天也找不到自己喜欢的,加载速度还比较慢。
索性就写了一个脚本,直接一直爬壁纸,你看几张壁纸的时间就能下载几十张壁纸,速度之快。
废话不多说直接附上源代码。
注:本程序执行会在桌面创建一个img的文件夹
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 =
med_url = []
category_dict = {
'1':["推荐", '','disorder=true&',skip,'','hot'],
'2':["最新", '','',skip,'',order],
'3':["美女", 'category/4e4d610cdf714d2966000000/','',skip,'category%2F4e4d610cdf714d2966000000%2F',order],
'4':["动漫", 'category/4e4d610cdf714d2966000003/','',skip,'category%2F4e4d610cdf714d2966000003%2F',order],
'5':["风景", 'category/4e4d610cdf714d2966000002/','',skip,'category%2F4e4d610cdf714d2966000002%2F',order],
'6':["游戏", 'category/4e4d610cdf714d2966000007/','',skip,'category%2F4e4d610cdf714d2966000007%2F',order],
'7':["文字", 'category/5109e04e48d5b9364ae9ac45/','',skip,'category%2F5109e04e48d5b9364ae9ac45%2F',order],
'8':["视觉", 'category/4fb479f75ba1c65561000027/','',skip,'category%2F4fb479f75ba1c65561000027%2F',order],
'9':["情感", 'category/4ef0a35c0569795756000000/','',skip,'category%2F4ef0a35c0569795756000000%2F',order],
'10':["设计", 'category/4fb47a195ba1c60ca5000222/','',skip,'category%2F4fb47a195ba1c60ca5000222%2F',order],
'11':["明星", 'category/5109e05248d5b9368bb559dc/','',skip,'category%2F5109e05248d5b9368bb559dc%2F',order],
'12':["物语", 'category/4fb47a465ba1c65561000028/','',skip,'category%2F4fb47a465ba1c65561000028%2F',order],
'13':["男人", 'category/4e4d610cdf714d2966000006/','',skip,'category%2F4e4d610cdf714d2966000006%2F',order],
'14':["机械", 'category/4e4d610cdf714d2966000005/','',skip,'category%2F4e4d610cdf714d2966000005%2F',order],
'15':["城市", 'category/4fb47a305ba1c60ca5000223/','',skip,'category%2F4fb47a305ba1c60ca5000223%2F',order],
'16':["动物", 'category/4e4d610cdf714d2966000001/','',skip,'category%2F4e4d610cdf714d2966000001%2F',order],
'17':["影视", 'category/4e58c2570569791a19000000/','',skip,'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)
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
url = url_template.format(item, item, item, item, item)
xh(url, item)
item = item+int(16)
category_dict = item
text = input('“q”键退出,Enter继续执行,“m”键显示目录\n请输入命令:')
感谢大家的阅读
修复桌面创建文件夹错误的问题
import requestsimport 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 =
med_url = []
category_dict = {
'1': ["推荐", '', 'disorder=true&', skip, '', 'hot'],
'2': ["最新", '', '', skip, '', order],
'3': ["美女", 'category/4e4d610cdf714d2966000000/', '', skip, 'category%2F4e4d610cdf714d2966000000%2F', order],
'4': ["动漫", 'category/4e4d610cdf714d2966000003/', '', skip, 'category%2F4e4d610cdf714d2966000003%2F', order],
'5': ["风景", 'category/4e4d610cdf714d2966000002/', '', skip, 'category%2F4e4d610cdf714d2966000002%2F', order],
'6': ["游戏", 'category/4e4d610cdf714d2966000007/', '', skip, 'category%2F4e4d610cdf714d2966000007%2F', order],
'7': ["文字", 'category/5109e04e48d5b9364ae9ac45/', '', skip, 'category%2F5109e04e48d5b9364ae9ac45%2F', order],
'8': ["视觉", 'category/4fb479f75ba1c65561000027/', '', skip, 'category%2F4fb479f75ba1c65561000027%2F', order],
'9': ["情感", 'category/4ef0a35c0569795756000000/', '', skip, 'category%2F4ef0a35c0569795756000000%2F', order],
'10': ["设计", 'category/4fb47a195ba1c60ca5000222/', '', skip, 'category%2F4fb47a195ba1c60ca5000222%2F', order],
'11': ["明星", 'category/5109e05248d5b9368bb559dc/', '', skip, 'category%2F5109e05248d5b9368bb559dc%2F', order],
'12': ["物语", 'category/4fb47a465ba1c65561000028/', '', skip, 'category%2F4fb47a465ba1c65561000028%2F', order],
'13': ["男人", 'category/4e4d610cdf714d2966000006/', '', skip, 'category%2F4e4d610cdf714d2966000006%2F', order],
'14': ["机械", 'category/4e4d610cdf714d2966000005/', '', skip, 'category%2F4e4d610cdf714d2966000005%2F', order],
'15': ["城市", 'category/4fb47a305ba1c60ca5000223/', '', skip, 'category%2F4fb47a305ba1c60ca5000223%2F', order],
'16': ["动物", 'category/4e4d610cdf714d2966000001/', '', skip, 'category%2F4e4d610cdf714d2966000001%2F', order],
'17': ["影视", 'category/4e58c2570569791a19000000/', '', skip, '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 :
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)
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
url = url_template.format(item, item, item, item, item)
xh(url, item)
item = item+int(16)
category_dict = item
text = input('“q”键退出,Enter继续执行,“m”键显示目录\n请输入命令:')
kafei000 发表于 2021-8-22 19:17
感谢楼主,这个是接口,可以分享下网站吗,我想学习学习
这是一个壁纸软件的接口,没有在软件中发现有官网的链接或者是网页版的,我是通过抓包获取的,软件不太方便分享 正需要,谢谢 感谢,可以下高清壁纸了 支持一下原创,不错。 nice,感谢分享。 很不错哦 支持分享!! 支持一下原创,不错。 谢谢分享,学习PY的来了。 正需要这个好资源。谢谢分享。 谢谢大佬分享。。试下