必应 bing.com 背景图下载
必应有一个 API 可以获取背景图的信息:
1 |
http://cn.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1 |
其中,idx 为向后的天数,idx<=10. n 为获取信息的条数,n<10.
返回json格式的数据:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
{ "images": [ { "startdate": "20170405", "fullstartdate": "201704051600", "enddate": "20170406", "url": "/az/hprichbg/rb/FreshSalt_ZH-CN12818759319_1920x1080.jpg", "urlbase": "/az/hprichbg/rb/FreshSalt_ZH-CN12818759319", "copyright": "淡水和盐水在埃斯塔蒂特附近的三河河口交汇,西班牙 (© Yann Arthus-Bertrand/Getty Images)", "copyrightlink": "http://www.bing.com/search?q=L'Estartit&form=hpcapt&mkt=zh-cn", "quiz": "/search?q=Bing+homepage+quiz&filters=WQOskey:%22HPQuiz_20170405_FreshSalt%22&FORM=HPQUIZ", "wp": true, "hsh": "800425f6986718006147107f1e622f39", "drk": 1, "top": 1, "bot": 1, "hs": [] } ], "tooltips": { "loading": "正在加载...", "previous": "上一个图像", "next": "下一个图像", "walle": "此图片不能下载用作壁纸。", "walls": "下载今日美图。仅限用作桌面壁纸。" } } |
有这些信息,就可以每天抓取bing的背景图了
附 Python 脚本:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# -*- coding:utf-8 -*- import requests from datetime import * from bs4 import BeautifulSoup import os import sys import re import json def loadImg(url,headers,cookies): r = requests.get(url=url,headers = headers, cookies=cookies) if not r: return js = json.loads(r.text.encode('UTF-8')) imgurl = js["images"][0]['url'] imgurl = 'http://www.bing.com/' + imgurl; print imgurl pos = imgurl.rfind('/') imgname = imgurl[pos+1:len(imgurl)] imgPath = lcdir + "/" + str(date.today()) + "_" + imgname r = requests.get(imgurl,headers=headers) with open(imgPath, 'wb') as f: for chunk in r.iter_content(1024): f.write(chunk) f.close() if __name__ == '__main__': url = r'http://cn.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1&nc=1361089515117&FORM=HYLH1' lcdir = "/home/user/bing_img" if os.path.exists(lcdir) == False: os.mkdir(lcdir) headers = {'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) \ AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36', 'Accept-Encoding':'gzip, deflate, sdch'} cookies=dict(ENSEARCH='BENVER=0') loadImg(url,headers,cookies) |
附:Win10锁屏壁纸
锁屏壁纸可能会保存在以下两个地方:
1 2 3 |
%user%\AppData\Local\Packages\Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy\LocalState\Assets C:\Windows\Web\Screen |
其中 Assets 下的文件比较杂,且都是没有后缀名的。可以将Assets文件复制出来,并重命令:
1 |
ren * *.jpg |
即可找出锁屏壁纸