如何让phantomjs查看etc hosts文件

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

标签: javascript phantomjs hosts

我想查看我的angular.js应用程序的外观。 我有phantomjs的问题。 我想首先查看我的/ etc / hosts文件

phantonjs script.js http://local.app/some/path some / path.html

这可能吗?

接下来是script.js的内容

 "use strict";
var fs = require('fs');
var system = require('system');

    var args = system.args;
    var url = args[1];
    var fileName = args[2] || 'result.html';

    function waitFor(testFx, onReady, timeOutMillis) {
        var maxtimeOutMillis = timeOutMillis ? timeOutMillis : 8000, //< Default Max Timout is 3s
            start = new Date().getTime(),
            condition = false,
            interval = setInterval(function() {
                if ( (new Date().getTime() - start < maxtimeOutMillis) && !condition ) {
                    // If not time-out yet and condition not yet fulfilled
                    condition = (typeof(testFx) === "string" ? eval(testFx) : testFx()); //< defensive code
                } else {
                    if(!condition) {
                        // If condition still not fulfilled (timeout but condition is 'false')
                        console.log("'waitFor()' timeout");
                        phantom.exit(1);
                    } else {
                        // Condition fulfilled (timeout and/or condition is 'true')
                        console.log("'waitFor()' finished in " + (new Date().getTime() - start) + "ms.");
                        typeof(onReady) === "string" ? eval(onReady) : onReady(); //< Do what it's supposed to do once the condition is fulfilled
                        clearInterval(interval); //< Stop this interval
                    }
                }
            }, 100); //< repeat check every 250ms
    };


    var page = require('webpage').create();

    // Open Twitter on 'sencha' profile and, onPageLoad, do...
    page.open(url, function (status) {
        // Check for page load success
        if (status !== "success") {
            console.log("Unable to access network");
        } else {
        console.log("Rendering...");
            // Wait for 'signin-dropdown' to be visible
            waitFor(function() {
                // Check in the page if a specific element is now visible
                return page.evaluate(function() {
                    return window.prerenderReady;
                });
            }, function() {
               console.log("Page rendered and saved to " + fileName);
            fs.write(fileName, page.content, 'w');
               phantom.exit();
            });
        }
    });

0 个答案:

没有答案