The PHP Bing Wallpaper Bot Crawler


The Bing has updated a wall paper everyday and we can create a PHP script to crawl it automatically everyday, which can be set to crontab job daily.

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
// en-US, zh-CN, ja-JP, en-AU, en-UK, de-DE, en-NZ
$url = 'http://www.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1&mkt=';
$resolution = '1920x1080';
 
// language options
$locale = array(
  "en-US",
  "zh-CN",
  "ja-JP",
  "en-AU",
  "en-UK",
  "de-DE",
  "en-NZ"
);
 
// parameters
$today = date("Y-m-d");
$ip = "VPS Server";
 
foreach ($locale as $lang) {
  $URL = $url . $lang;
  $data = file_get_contents($URL);
  $json = json_decode(trim($data), true);
  if ($json) {
    $images = $json['images'];
    foreach ($images as $image) {
      $urlbase = $image['urlbase'];
      $image_url = 'http://www.bing.com' . $urlbase . '_' . $resolution . '.jpg';
      $copyright = $image['copyright'];
      // now you can save the picture at $image_url with the title $copyright
    }
  }
}
// en-US, zh-CN, ja-JP, en-AU, en-UK, de-DE, en-NZ
$url = 'http://www.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1&mkt=';
$resolution = '1920x1080';

// language options
$locale = array(
  "en-US",
  "zh-CN",
  "ja-JP",
  "en-AU",
  "en-UK",
  "de-DE",
  "en-NZ"
);

// parameters
$today = date("Y-m-d");
$ip = "VPS Server";

foreach ($locale as $lang) {
  $URL = $url . $lang;
  $data = file_get_contents($URL);
  $json = json_decode(trim($data), true);
  if ($json) {
    $images = $json['images'];
    foreach ($images as $image) {
      $urlbase = $image['urlbase'];
      $image_url = 'http://www.bing.com' . $urlbase . '_' . $resolution . '.jpg';
      $copyright = $image['copyright'];
      // now you can save the picture at $image_url with the title $copyright
    }
  }
}
bing_brand_logo_bid_1 The PHP Bing Wallpaper Bot Crawler code crontab php programming languages search

Bing Wallpaper Crawler

The API from Bing returns a JSON-encoded structure which contains the URL of the image and the copyright string which can be used to describe the wall paper. This has now been set up as a daily crontab job so you can find all Bing wall papers using Tag: BingEverydayWallpaperPicture.

Note that you can also use API to fetch, according to the API documents.

https://helloacm.com/api/pictures/search/?key=BingEverydayWallpaperPicture

How to Show a Random Bing Photo?

According to the API, you can use the following HTML code:

1
<img src='https://uploadbeta.com/api/pictures/random/?key=BingEverydayWallpaperPicture' style='max-width:50%'>
<img src='https://uploadbeta.com/api/pictures/random/?key=BingEverydayWallpaperPicture' style='max-width:50%'>

To obtain a random Bing Photo, like the following (you can press Ctrl + F5 to clear the browser image caches):

?key=BingEverydayWallpaperPicture The PHP Bing Wallpaper Bot Crawler code crontab php programming languages search

You can also use the following cached version (refreshed every 30 minutes):

https://uploadbeta.com/api/pictures/random/?cached&key=BingEverydayWallpaperPicture

–EOF (The Ultimate Computing & Technology Blog) —

GD Star Rating
loading...
490 words
Last Post: How to Hide a File in JPEG under Linux Shell?
Next Post: How to Add Disqus if Comments are Closed in WordPress?

The Permanent URL is: The PHP Bing Wallpaper Bot Crawler

2 Comments

Leave a Reply