使用PhantomJS重新渲染动态页面

时间:2016-06-06 09:39:42

标签: javascript phantomjs

我正在尝试定期重新呈现页面http://www.investing.com/currencies/usd-rub

此页面包含动态图表,但看起来PhantomJS只渲染了一次。

var page = new WebPage();

var testindex = 0, loadInProgress = false, workInProgress = false;

page.onConsoleMessage = function (msg) {
    console.log(msg);
};

page.onLoadStarted = function () {
    loadInProgress = true;
    console.log("load started");
};

page.onLoadFinished = function () {
    loadInProgress = false;
    console.log("load finished");
};

var steps = [
    function () {
        workInProgress = true;
        page.open("http://www.investing.com/currencies/usd-rub", function (status) {
            if (status === "success") {
                page.includeJs("http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js", function () {
                    page.evaluate(function () {
//                console.log("$(\".chartWrap\").html() -> " + $(".chartWrap").html());
                    });

                    var bb = page.evaluate(function () {
//                return document.getElementsByClassName("chartWrap")[0].getBoundingClientRect();
                        $(".generalOverlay").remove();
                        $(".mainPopUpContainer").remove();

                        console.log($("#chart-info-last").html());
                        var div = $(".chartWrap")[0].getBoundingClientRect();
                        return div;
                    });

//                    page.clipRect = {
//                        top: bb.top,
//                        left: bb.left,
//                        width: bb.width,
//                        height: bb.height
//                    };

                    console.log("Start render usd-rub.png");
                    page.render('usd-rub.png');
                    console.log("End of render usd-rub.png");

                    workInProgress = false;



                });

            }
        });
    },
    function () {
    },
];


steps[0]();

interval = setInterval(function () {


    if (!loadInProgress && !workInProgress) {
        console.log("Start render usd-rub.png");

        page.evaluate(function () {
            $('body').hide();
            $('body').show();
            console.log($("#chart-info-last").html());
        });

        page.render('usd-rub.png');


        console.log("End of render usd-rub.png");
    }

}, 7000);

此脚本仅显示一个值,而不是动态值。

Start render usd-rub.png
65.6848
End of render usd-rub.png
Start render usd-rub.png
65.6848
End of render usd-rub.png
Start render usd-rub.png
65.6848
End of render usd-rub.png
Start render usd-rub.png
65.6848
End of render usd-rub.png
Start render usd-rub.png
65.6848
End of render usd-rub.png
Start render usd-rub.png
65.6848
End of render usd-rub.png
Start render usd-rub.png
65.6848
End of render usd-rub.png

是否有可能重新渲染页面而不重新加载(重新加载需要花费很多时间,如我所见,但我需要快速响应)?

谢谢!

0 个答案:

没有答案