美文网首页工作生活Python入门100天
python下载每日必应壁纸

python下载每日必应壁纸

作者: Hope_加贝 | 来源:发表于2019-07-04 09:29 被阅读0次
#-*-coding:utf-8-*-
from bs4 import  BeautifulSoup
import  requests
import  time
import os
import  PyWallpaper
import win32api
import  win32gui
import  win32con
from PIL import  Image

def set_wallpaper_from_bmp(bmp_path):
    reg_key = win32api.RegOpenKeyEx(win32con.HKEY_CURRENT_USER, "Control Panel\\Desktop", 0, win32con.KEY_SET_VALUE)
    win32api.RegSetValueEx(reg_key, "WallpaperStyle", 0, win32con.REG_SZ, "2")
    win32api.RegSetValueEx(reg_key, "TileWallpaper", 0, win32con.REG_SZ, "0")
    win32gui.SystemParametersInfo(win32con.SPI_SETDESKWALLPAPER, bmp_path, win32con.SPIF_SENDWININICHANGE)


def set_wallpaper(file_path):
    bmpImage = Image.open(file_path)
    img_dir = "D:\wallpaper\\"
    print("IMage:dir")
    print(img_dir)
    new_bmp_path = os.path.join(img_dir,'wallpaper.bmp')
    bmpImage.save(new_bmp_path,"BMP")
    set_wallpaper_from_bmp(new_bmp_path)



content = requests.get("https://cn.bing.com/?mkt=zh-CN").text
soup = BeautifulSoup(content,'html.parser')
image_url = "https://cn.bing.com/" + soup.find(id="bgLink")["href"]
print(image_url)
str_time = time.strftime("%Y-%m-%d")
month = time.strftime("%m")
img = requests.get(image_url)

image_path = r"D:\bing\%s"%(month)
image_full_path = r"D:\bing\%s\%s.jpg"%(month,str_time)



if img.status_code == 200:
    folder = os.path.exists(image_path)
    if not folder:
            os.mkdir(image_path)
    with open(r"D:\bing\%s\%s.jpg"%(month,str_time),'wb') as file:
        file.write(img.content)
        set_wallpaper(image_full_path)

相关文章

  • Python下载必应今日图片

    利用Python下载必应每日壁纸,其实很简单,每日壁纸,这个网址指向了今天的必应壁纸,我们只需要把图片保存下来就好...

  • python下载每日必应壁纸

  • 高清壁纸网站

    高清壁纸网站地址:电脑壁纸 1.每日更新最新壁纸; 2.多种分类壁纸; 3.必应美图; 4.每日英语; 5.下载壁...

  • Automator定时任务

    以每天定时下载必应并更换为壁纸为例 选择执行 代码看这里自动下载必应每日一图并设置为mac壁纸 - 简书之后保存然...

  • 必应每日壁纸

    Daily Wallpaper Bing Edition on the Mac App Store

  • 必应每日壁纸

    每日壁纸API 必应首页的壁纸比较好看,可以当作网站或者博客的背景图,但是要是静态网站或者博客每天换就有一些麻烦了...

  • Python3 下载必应背景图代码更新

    本文首发于个人博客。 几年前写过一篇用 Python 下载每日必应背景图的方法,不过由于必应网站更新,之前的方法失...

  • 高清壁纸网站都在这儿,桌面从此更精致

    1.必应壁纸 网址链接:https://bing.ioliu.cn/ 推荐指数:4.0星 优点:必应壁纸出品自微软...

  • win下自己常用软件

    以免忘记。 Listary 文件搜索 f.lux 护眼 cmder 命令行替代 ss 科学上网 每日必应 壁纸 m...

  • UWP使用必应每日壁纸(一)

    必应壁纸接口我在网上找了很多大体都是第三方经过加工,所以稳定性不太清楚能不能长久使用也不清楚。于是乎我找了很久在h...

网友评论

    本文标题:python下载每日必应壁纸

    本文链接:https://www.haomeiwen.com/subject/sookhctx.html