Nodejs Download Bing China wallpaper

Source: Internet
Author: User


Bing Wallpaper is very nice, download it every day when the desktop is still good, in fact, the capture image method is very simple, but the image URL still have to do some work to check. Take some time, or find the Bing China HD Wallpaper (1980*1080) address, here is the code for Nodejs to grab the picture:

/* Download Bing China wallpaper To this directory the resolution is 1980*1080, can be set */var http = require (' http '); Var fs = require ( ' FS ');var options = {    hostname:  ' cn.bing.com ',     port: 80,    path:  '/hpimagearchive.aspx?idx=0&n=1 ',     method:  ' GET '};var req = http.request (options, function (res)  {     var reg = new regexp ("<url>/az/hprichbg/rb/(. *) _1366x768.jpg</url> ");    var body =  ';     res.on (' Data ',  function ( Chunk)  {        body += chunk;    } ). On (' End ',  function ()  {        reg.test (body);         var img = RegExp.$1;         consolE.log (IMG);         writestream = fs.createwritestream (img  +  "_1920x1080.jpg");         http.get (' http://s.cn.bing.net/ az/hprichbg/rb/'  + img +  "_1920x1080.jpg",  function (RES)  {             res.pipe (Writestream);         })         writestream.on (' Finish ',  function ()  {            console.log (' Done ');         });     })     res.on (' Error ',  function (e)  {        console.log (e.message);     })}); Req.end ();

(⊙o⊙) ..., the code is very small. But get the wallpaper on the line.

Next, there are a few things you can do:

For the win user, you can write a program in C #, set the wallpaper as the system desktop, call the Windows API interface, and then write a scheduled task, execute the bat script every day, script do 2 things, 1:node run the above script download wallpaper, 2, call C # program set wallpaper.

I do not work under win, so C # program does not write:)

Nodejs Download Bing China wallpaper

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.