使用的Python,接口是https://bing.ee123.net/ ,大佬的免费接口。
首先是代码,我这里下载的是4K的壁纸,后面有需要的可以自己更换分辨率。
代码:
import requests import os from datetime import datetime, timedelta from requests.packages.urllib3.exceptions import InsecureRequestWarning # 忽略不安全请求警告 requests.packages.urllib3.disable_warnings(InsecureRequestWarning) def download_bing_wallpapers(start_date, end_date): base_url = "https://bing.ee123.net/img/" size = "UHD" output_dir = "bing_wallpapers" # 创建保存壁纸的文件夹 if not os.path.exists(output_dir): os.makedirs(output_dir) session = requests.Session() session.verify = False current_date = start_date while current_date <= end_date: date_str = current_date.strftime('%Y%m%d') params = { 'date': date_str, 'size': size, 'type': 'json' } response = session.get(base_url, params=params) # 检查请求是否成功 if response.status_code == 200: try: data = response.json() print(f"Response for {date_str}: {data}") # 打印返回的JSON内容 image_url = data.get('imgurl') # 使用 'imgurl' 获取图片URL if image_url: image_name = f"{date_str}.jpg" image_path = os.path.join(output_dir, image_name) # 下载图片 img_response = session.get(image_url) if img_response.status_code == 200: with open(image_path, 'wb') as img_file: img_file.write(img_response.content) print(f"Downloaded: {image_name}") else: print(f"Failed to download image from {image_url}") else: print(f"No 'imgurl' found in the response for {date_str}") except ValueError: print(f"Failed to decode JSON response for {date_str}") else: print(f"Failed to retrieve data for {date_str}, status code: {response.status_code}") current_date += timedelta(days=1) if __name__ == "__main__": # 设置开始日期和结束日期 start_date = datetime(2024, 1, 1) end_date = datetime(2024, 8, 11) download_bing_wallpapers(start_date, end_date)
壁纸打包下载:使用上方工具自行下载。
小白开箱即用版本下载:
使用说明:解压后双击bing_wallpaper_downloader.exe即可。
© 版权声明
本站专栏文章版权归作者所有,未经允许请勿转载。
相关文章
暂无评论...