loop through array of urls in phantomjs using javascript

牧云@^-^@ 提交于 2019-12-04 16:46:15
var urls = [
'http://www.google.com',
'http://www.facebook.com'
];


function process() {
    if (urls.length == 0) {
        phantom.exit();
    } else {
        //remove the first item of an array
        url = urls.shift();
        //open a page
        page = require('webpage').create();

        //store the requested url in a separate variable
        var currentUrl = url


        page.open(url, onFinishedLoading)

        page.onNavigationRequested = function(url, type, willNavigate, main) {
            console.log('\n' + currentUrl + '\nredirecting to \n' + url);
        }

    }
}

function onFinishedLoading(status) {

    console.log(status);
    page.release();
    process();
}

process();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!