crash - 150-180个网址后PhantomJS崩溃

标签 crash phantomjs httprequest

到目前为止,我的脚本运行良好,按顺序依次在文本文件中逐行加载了每个页面(page.open是异步的,页面对象是global =在新请求上被覆盖,这是一个大的clusterfuck,在运行多个page.open()时一次),匹配对特定域的每个请求并从中打印JSON值。

但是,如果我使用具有超过150个链接的.txt文件,它每次都会崩溃,并且大多数情况下都不会出现错误消息且没有崩溃转储,如下所示:

PhantomJS has crashed. Please read the crash reporting guide at http://phantomjs.org/crash-reporting.html and file a bug report at https://github.com/ariya/phantomjs/issues/new. Unfortunately, no crash dump is available. (Is %TEMP% (C:\Users\XXX\AppData\Local\Temp) a directory you cannot write?)



如果我多次运行它,我可以很容易地重现它,而一次或一次又一次都没关系。
如何预防车祸?如果Phantom无法处理我的脚本,那就没用了。

但是有时候我会崩溃转储:

PhantomJS has crashed. Please read the crash reporting guide at http://phantomjs.org/crash-reporting.html and file a bug report at https://github.com/ariya/phantomjs/issues/new. Please attach the crash dump file: C:\Users\XXX\AppData\Local\Temp\a4fd6af6-1244-44d3-8938-3aabe298c2fa.dmp



https://www.dropbox.com/s/i3qi5ed33mbblie/500%20links%20-a4fd6af6-1244-44d3-8938-3aabe298c2fa.dmp?dl=1

https://www.dropbox.com/s/najdz9fhdexvav1/500%20links-%2095ebab5c-859b-40e9-936b-84967471779b.dmp?dl=1

https://www.dropbox.com/s/1d2t8rtev85yf96/500%20links%20-%20d450c8e1-9728-41c7-ba52-dfef466f0222.dmp?dl=1

而且在极少数情况下,我什至会收到错误消息,Process Explorer表示该进程一次最多具有21个线程

QThread::start: Failed to create thread ()


console.log('Hello, world!');
var fs = require('fs');
var stream = fs.open('500sitemap.txt', 'r');
var webPage = require('webpage');
var i = 1;
var hasFound = Array();
var hasonLoadFinished = Array();

function handle_page(line) {
var page = webPage.create();
page.settings.loadImages = false;
page.open(line, function() {});

page.onResourceRequested = function(requestData, request) {
    var match = requestData.url.match(/example.de\/ac/g)
    if (match != null) {
        hasFound[line] = true;
        var targetString = decodeURI(JSON.stringify(requestData.url));
        var klammerauf = targetString.indexOf("{");
        var jsonobjekt = targetString.substr(klammerauf,     (targetString.indexOf("}") - klammerauf) + 1);
        targetJSON = (decodeURIComponent(jsonobjekt));
        var t = JSON.parse(targetJSON);
        console.log(i + "   " + t + "       " + t['id']);
        request.abort;
    } else {
        //hasFound = false;
        return;
    }

};
page.onLoadFinished = function(status) {    
    if (!hasonLoadFinished[line]) {
        hasonLoadFinished[line] = true;
        if (!hasFound[line]) {
            console.log(i + " :NOT FOUND: " + line);
            console.log("");
        }
        i++;
        setTimeout(page.close, 200);
        nextPage();
    }
}
};

function nextPage() {
var line = stream.readLine();
if (!line) {
    end = Date.now();
    console.log("");
    console.log(((end - start) / 1000) + " Sekunden");
    phantom.exit(0);
}
hasFound[line] = false;
hasonLoadFinished[line] = false;
handle_page(line);
}

start = Date.now();
nextPage();

最佳答案

/ edit在3836个链接后崩溃了1.9.8 ....重新启动.......

似乎问题出在2.0版本中。经过1.9.8的挫折测试,并且-可以正常工作,使用的RAM减少了60%,并且没有因1000 Urls而崩溃。

github上的崩溃报告已完成,这是多么的轻松,它有效。

关于crash - 150-180个网址后PhantomJS崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32512914/

相关文章:

javascript - karma : Can't find variable: exports

phantomjs - 如何控制 PhantomJS 跳过下载某种资源?

javascript - casperJS 注入(inject) jQuery 失败

android无法解析json数据android

powershell - 如何在 PowerShell 中发布到 URL?

url - 在 Spring MVC 中获取当前 URL 的最佳方法是什么?

iphone - 如何知道从应用商店更新后第一个应用程序是否启动

android - Android 应用程序崩溃后向服务器发送日志文件

c - 初学者的程序总是崩溃

java - Eclipse 和 Netbeans 中的 JVM 偶尔会崩溃