#!/usr/bin/env python3
# -*- coding: utf-8 -*-
__author__ = 'jiangwenwen'
from bs4 import BeautifulSoup
import requests
import time
import os
import wallpaper
# 获取图片地址
content = requests.get("https://cn.bing.com/?mkt=zh-CN").text
soup = BeautifulSoup(content, "lxml")
img_url = "https://cn.bing.com/" + soup.find(id="bgLink")["href"]
print(img_url)
str_time = time.strftime("%Y-%m-%d")
month = time.strftime("%m")
# 下载图片并保存到指定位置
img = requests.get(img_url)
img_path = r"H:ing\%s" % (month)
if img.status_code == 200:
# 如果文件夹不存在则创建
folder = os.path.exists(img_path)
if not folder:
os.mkdir(img_path)
open(r"H:ing\%s\%s.jpg" % (month, str_time), 'wb').write(img.content)
# 设置壁纸
wallpaper.set_wallpaper(r"H:ing\%s\%s.jpg" % (month, str_time))