如何在casperjs中使用babel-polyfill?

时间:2019-07-25 08:57:09

标签: javascript phantomjs casperjs polyfills babel-polyfill

我正在使用babel-polyfill,但是在我的机器上不起作用。实际上,我打开一个URL并尝试获取页面的所有资源。一些资源是js文件,它们动态运行并创建其他js文件或重定向到另一个资源。我需要这些资源来检查页面像素。

错误:+++ DBDM-ERROR> interest-profile.js:TypeError:未定义不是函数(正在评估'Math.log10(scoreMap [event] * relevance * 100)') 档案:https://1.www.s81c.com/common/stats/ida_stats.js 行:5 功能:添加

这是一个资源文件“ ida_stats.js”,该文件正在动态运行并创建其他js文件和像素URL。但是由于某些动态参数,它无法创建动态URL。我正在使用Casper js版本1.1.4和phantom js版本2.1.1 NPM版本6.4.1 python版本是2.7.16机器操作系统是Ubuntu。

请帮助解决此问题的人

代码如下:-

var casper = require('casper').create({
    verbose: true,
    pageSettings: {
        loadImages: true,
        loadPlugins: true,
        webSecurityEnabled: false,
        loadCSS: true,
        loadJS: true,
        javascriptEnabled: true,
        ignoreSslErrors: true,
        localToRemoteUrlAccessEnabled: true,
        resourceTimeout: 50000,
        sslProtocol: "any",
        userAgent: "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36"
    }
});


casper.options.clientScripts.push(pluginPath + "src/Shell/polyfill.js")
casper.start();

casper.on("page.error", function (msg, trace) {
    this.echo("Error:    " + msg, "ERROR");
    this.echo("file:     " + trace[0].file, "WARNING");
    this.echo("line:     " + trace[0].line, "WARNING");
    this.echo("function: " + trace[0]["function"], "WARNING");
});

casper.on("resource.requested", function (resource, request) {
    var params = headers(resource.headers);
    if (typeof (params["Referer"]) != 'undefined' || typeof (casper.redirectList[params["Referer"]]) != 'undefined') {
        if (typeof (params["Referer"]) != 'undefined') {
            var r = params["Referer"];
        } else if (typeof (casper.redirectList[params["Referer"]]) != 'undefined') {
            var r = casper.redirectList[params["Referer"]];
        }
        while (typeof (casper.redirectList[r]) != 'undefined') {
            r = casper.redirectList[r];
        }
        if (typeof (casper.urlList[r]) == "undefined") {
            casper.urlList[r] = [];
        }
        var pa = {};
        var p = resource.url.split(/[\s?&]+/);
        for (pp = 0; pp < p.length; pp++) {
            var ppp = p[pp].split("=");
            pa[ppp.shift()] = ppp.join('=');
        }
        pa['url'] = resource.url;
        casper.urlList[r].push(pa);
    }
});



casper.on('resource.received', function (response) {
    if (response.redirectURL != null && response.redirectURL != '') {
        casper.redirectList[response.redirectURL] = response.url;
    } else if (response.status == 301) {
        var params = headers(response.headers);
        var redirectURL = response.url.split('/');
        redirectURL = redirectURL[0] + '/' + redirectURL[1] + '/' + redirectURL[2] + params['Location'];
        var u = response.url;
        while (casper.redirectList[u]) {
            u = casper.redirectList[u];
        }
        casper.redirectList[redirectURL] = u;
    }
    casper.allResourcesStatus[response.url] = response.status;
});





casper.each(jsonOfPages, function (casper, link) {
    if (!pattern.test(link.url)) {
        link.url = "https://" + link.url;
    }
    link.url = "https://www.ibm.com/za-en/services/cloud";
    //Static Url for test
    casper.thenOpen(link.url, function (response) {
       //Code work with resources
    });
});

casper.run();

0 个答案:

没有答案