关注网页的更新状况,了解最新的handsup 消息.

// 第一部分是网页截图和源码保存
// upon page load.

var fs = require("fs"); 
var resourceWait  = 300,
    maxRenderWait = 10000,
 url='http://handsup-releases.eu/';

var page          = require('webpage').create(),
    count         = 0,
    forcedRenderTimeout,
    renderTimeout;

page.settings = {
   userAgent: 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.75 Safari/537.36',
  	  javascriptEnabled: true,
      loadImages: true
};
page.viewportSize = { width: 1280, height : 1024 };

function doRender() {
    page.render('twitter.png');
     fs.write('1.html', page.content, 'w');
    phantom.exit();
}

page.onResourceRequested = function (req) {
    count += 1;
    console.log('> ' + req.id + ' - ' + req.url);
    clearTimeout(renderTimeout);
};

page.onResourceReceived = function (res) {
    if (!res.stage || res.stage === 'end') {
        count -= 1;
        console.log(res.id + ' ' + res.status + ' - ' + res.url);
        if (count === 0) {
            renderTimeout = setTimeout(doRender, resourceWait);
        }
    }
};

page.open(url, function (status) {
    if (status !== "success") {
        console.log('Unable to load url');
      //  phantom.exit();
    } else {
        forcedRenderTimeout = setTimeout(function () {
            console.log(count);
            doRender();
        }, maxRenderWait);
    }
});

  

posted @ 2017-01-26 13:30  公众号python学习开发  阅读(210)  评论(0编辑  收藏  举报