必应搜索的背景图片每天都会更新一次,能不能用js获取它图片的url呢
Google一番找到它的API,以下两个都一样的。
http://cn.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1
http://www.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1&mkt=zh-CN
直接在浏览器打开是如下的json,要拿到的就是url,直接在一个页面用js获取存在跨域问题,可以用代理工具https://jsonp.afeld.me/ 我用的是第二个方法,把上面的api输入,

点击go得到一个经过代理后的api,如下
1
| https://jsonp.afeld.me/?url=http%3A%2F%2Fcn.bing.com%2FHPImageArchive.aspx%3Fformat%3Djs%26idx%3D0%26n%3D1
|
然后直接获取里面的url就可以了,请看下面demo地址。
DEMO地址
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
| { "images": [ { "startdate": "20160413", "fullstartdate": "201604131600", "enddate": "20160414", "url": "http://s.cn.bing.net/az/hprichbg/rb/GareSaintLazare_ZH-CN6611772290_1920x1080.jpg", "urlbase": "/az/hprichbg/rb/GareSaintLazare_ZH-CN6611772290", "copyright": "法国,巴黎圣拉扎尔火车站 (© Hal Bergman/Getty Images)", "copyrightlink": "http://www.bing.com/search?q=%E5%B7%B4%E9%BB%8E%E5%9C%A3%E6%8B%89%E6%89%8E%E5%B0%94%E8%BD%A6%E7%AB%99&form=hpcapt&mkt=zh-cn", "wp": true, "hsh": "2a914f203e137533bae7c9fc3c391696", "drk": 1, "top": 1, "bot": 1, "hs": [ ], "msg": [ { "title": "今日图片故事", "link": "http://www.bing.com/search?q=%E5%B7%B4%E9%BB%8E%E5%9C%A3%E6%8B%89%E6%89%8E%E5%B0%94%E8%BD%A6%E7%AB%99&form=pgbar1&mkt=zh-cn", "text": "巴黎圣拉扎尔火车站" } ] } ], "tooltips": { "loading": "正在加载...", "previous": "上一页", "next": "下一页", "walle": "此图片不能下载用作壁纸。", "walls": "下载今日美图。仅限用作桌面壁纸。" } }
|