好友
阅读权限 10
听众
最后登录 1970-1-1
1. 配置环境
安装python3环境
python3
2. 安装pywin32
3. 安装requests
4. 运行代码
新建一个test.py文件并将代码粘贴到文件保存
[Python] 纯文本查看 复制代码
# encoding:utf-8
import win32gui,win32con,win32api
import os
import requests
import random
import time
from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
def setWallpaper(imagepath):
k = win32api.RegOpenKeyEx(win32con.HKEY_CURRENT_USER,"Control Panel\\Desktop",0,win32con.KEY_SET_VALUE)
win32api.RegSetValueEx(k, "WallpaperStyle", 0, win32con.REG_SZ, "2") # 0 居中正常大小,2 拉伸铺满全屏
win32api.RegSetValueEx(k, "TileWallpaper", 0, win32con.REG_SZ, "0")
win32gui.SystemParametersInfo(win32con.SPI_SETDESKWALLPAPER,imagepath, 1+2)
if __name__ == '__main__':
headers = {"User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.79 Safari/537.36"}
data_url= "https://pvp.qq.com/web201605/js/herolist.json"
response= requests.get(data_url,headers=headers,verify=False)
if response.status_code == 200:
json_str = response.text
hero_list = eval(json_str)
enames = []
imgbox = []
for hero in hero_list:
ename = hero["ename"]
number = 1
try:
skin_name = hero["skin_name"]
number = len(skin_name.split("|"))
except Exception as e:
pass
for i in range(number):
url = "https://game.gtimg.cn/images/yxzj/img201606/skin/hero-info/" + str(ename) + '/' + str(ename)+"-bigskin-" + str(i+1) + ".jpg";
imgbox.append(url)
while True:
index = random.randint(0,len(imgbox)-1)
url = imgbox[index]
filename = os.getcwd()+"/"+url.split("/")[-1]
response= requests.get(url,headers=headers,verify=False)
imgbytes = response.content
with open(filename,'wb') as f:
f.write(imgbytes)
setWallpaper(filename)
os.remove(filename)
time.sleep(1)
首先打开命令行,运行命令:
python test.py #python已配置环境变量
[换成自己安装路径,运行不了路径加""] D:\Python3\python.exe test.py #python未配置环境变量
6. bat运行,新建一个test.bat文件
例如:(rem[注释])
[PowerShell] 纯文本查看 复制代码
@echo off
rem bat和 py文件在同目录
python test.py
rem "D:\Python3\python.exe" test.py
rem bat和 py文件不在同目录
rem python C:\test.py
rem "D:\Python3\python.exe" D:\test.py
exit
脚本在C盘出现这个错误,需要以管理员身份运行,所有放其他盘 PermissionError: [Errno 13] Permission denied:
然后双击
7. 运行结果(部分截图)
8. 只玩玩就行,不要长时间运行
免费评分
查看全部评分
发帖前要善用【论坛搜索 】 功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。