自动下载必应主页图片做壁纸

本文介绍了一个简单的Python脚本,用于自动下载必应每日壁纸并设置为Windows系统的桌面背景。通过定时任务实现每天自动更换壁纸的功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  1. 前言
    需要python环境,安装requests等模块
    只在win10搞过,其它不知道行不行
    存放路径可以自己修改(Administrator是我的用户名)

  2. 在windows设置中将背景设为“幻灯片放映”,假设目录设置为C:\Users\Administrator\Pictures\bg
    设置图片切换频率,比如30min

  3. 写python脚本执行下载图片的动作,脚本路径名称C:\Users\Administrator\Pictures\bg\script\dlbg.py

import requests
import re
import time

home = 'https://cn.bing.com/'
response = requests.get(home)

pattern = '#bgDiv\{ opacity: 1;background-image:url\([^\)]*\)'
s1 = re.search(pattern, response.text)
s2 = s1.group()[40:-1]

name = str(time.strftime('%Y-%m-%d' ,time.localtime(time.time())))
picture = requests.get(home + s2)
with open('C:\\Users\\Administrator\\Pictures\\bg\\' + name + '.jpg', 'wb') as file:
    file.write(picture.content)
  1. 写批处理脚本用来执行python脚本,脚本路径名称C:\Users\Administrator\Pictures\bg\script\dlbg.bat
@ python.exe C:\Users\Administrator\Pictures\bg\script\dlbg.py
  1. 设置windows定时任务,定时执行批处理脚本dlbg.bat,教程:
    https://jingyan.baidu.com/article/154b463130041128ca8f41c7.html
    定时任务的执行时间我这边是每天上午9点
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值