PhantomJS get JS refresh

时间:2016-04-15 15:10:08

标签: javascript c# phantomjs

I need to check every content change on a web site.

I wrote a PhantomJS function to get the whole web site. After reciving the web site I parse every row to get the data.

Now I want to hold the connection and recive all JS-updates.

What need I do to get the JS-updates?

I hope my question is clear.

Here some code explanations:

Pseudo HTML Website

<html>
    <head>...</head>
    <body>
        <div class="value-123" onload="(function() { setInterval(retrieveData(...), 5000); })">
            <!-- If retieveData finished, VALUE will change from e.g. 1.23 to 4.235 -->
            VALUE
        </div>
    </body>
</html>

My PhantomJS Code:

        const string cEndLine = "All output received";

        var sb = new StringBuilder();
        var p = new PhantomJS();
        p.OutputReceived += (sender, e) =>
        {
            if (e.Data == cEndLine)
            {
                callBack(sb.ToString());
            }
            else
            {
                sb.AppendLine(e.Data);
            }
        };
        p.RunScript(@"
                var page = require('webpage').create();
                page.settings.loadImages = false;
                page.viewportSize = { width: 1920, height: 1080 };
                page.onLoadFinished = function(status) {
                    if (status=='success') {
                        setTimeout(function() {
                            console.log(page.content);
                            console.log('" + cEndLine + @"');
                            phantom.exit();
                        }," + waitAfterPageLoad.TotalMilliseconds + @");
                    }
                };
                var url = '" + url + @"';
                page.open(url);", new string[0]);

0 个答案:

没有答案