用PHP获取Bing 每日图片

时间:2018-1-18    作者:晨曦    分类: 源码之家


都知道微软的Bing搜索引擎首页每天都会提供了一些有趣的图片,而这些图片很多都是有故事含义的,很多网友每天去访问bing首页都是为了这些图片而去的,那么怎么下载下来呢。

获取API接口:

通过抓包,可以发现:

http://www.bing.com/HpImageArchive.aspx?format=xml&idx=0&n=1

这里可以获取到无水印的图片

通过模拟UA,访问移动版。同样发现了API接口

http://cn.bing.com/cnhp/coverstory/

不过这里的图片是有水印的

代码:


  • <?php
  • /**
  • * 获取Bing每日壁纸 无水印
  • * @author myitmx
  • */
  • $str=file_get_contents('http://cn.bing.com/HPImageArchive.aspx?idx=0&n=1');
  • if(preg_match("/<url>(.+?)<\/url>/ies",$str,$matches)){
  • $imgurl='http://cn.bing.com'.$matches[1];
  • }
  • if($imgurl){
  • header('Content-Type: image/JPEG');
  • @ob_end_clean();
  • @readfile($imgurl);
  • @flush(); @ob_flush();
  • exit();
  • }else{
  • exit('error');
  • }
  • ?>

获取到的图片分辨率为:1366*768分辨率

效果:

bing 每日图片

图片地址:https://www.myitmx.com/bing/bing.php

本站API:

1920x1080分辨率:

https://www.myitmx.com/bing/api.php?resolution=1920x1080

1366x768分辨率:

https://www.myitmx.com/bing/api.php?resolution=1366x768


转自:枫叶博客

评论:

姜辰 2018-01-19 01:04
代码没毛病,但是你演示的挂了。
晨曦 2018-01-19 02:21
@姜辰:哪一个演示,点击链接进去就可以 我测试可用
@ ☆追梦☆ 2018-01-19 16:14
@晨曦:你也还在玩网站呢?
晨曦 2018-01-20 02:58
@@  ☆追梦☆:这话涵盖量很大啊