关于自动每日开机设置随机壁纸,之前我发过一个帖子;今天又改进了一下
随机取必应每日壁纸或360壁纸库(360壁纸库下的随机分类下的随机图片)
用的是python爬取并设置为电脑壁纸的;
设置开机自启动:
把.exe文件放在: C:\Users\你当前登录的用户名\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup 目录下 就可以直接开机自启动了。
下载地址:https://wwa.lanzouj.com/iRHwYdj32re
源代码:
[Python] 纯文本查看 复制代码 import requests
import json
import ctypes
import random
def bying():
r = requests.get('http://cn.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1')
res = r.content.decode('utf-8')
response = json.loads(res)
url = response['images'][0]['url']
url = 'http://cn.bing.com' + url
write(url)
def write(url):
a = requests.get(url)
path = r'D:\pic.png'
with open(path, 'wb') as f:
f.write(a.content)
ctypes.windll.user32.SystemParametersInfoW(20, 0, path, 0)
def bz360():
# 不要的壁纸分类
donot = [12, 29, 7, 22, 16]
# 1. 获取分类
imgTypesres = requests.get("http://cdn.apc.360.cn/index.php?c=WallPaper&a=getAllCategoriesV2&from=360chrome").content.decode('utf-8')
imgTypesres = json.loads(imgTypesres)
typeList = imgTypesres['data']
allTypeId = []
for i in typeList:
if int(i['id']) not in donot:
allTypeId.append(i['id'])
# 2. 随机取一个分类
reqType = random.choice(allTypeId)
# 3.随机取一个起始页(1-100)
reqStart = random.randint(1, 100)
# 获取图片数据
imgData = requests.get("http://wallpaper.apc.360.cn/index.php?c=WallPaper&a=getAppsByCategory&cid={0}&start={1}&count=1&from=360chrome".format(reqType, reqStart)).content.decode('utf-8')
imgData = json.loads(imgData)
url = imgData["data"][0]['url']
write(url)
if __name__ == '__main__':
# 随机选择必应或360
chose = random.randint(1, 3)
if chose == 1:
bying()
else:
bz360()
撒花~ 本文完结, 如对您有所帮助 免费评分走一走
原文地址:http://blog.zhanghaoran.ren/detail/10.html
by mbz |