3
我想通過使用PhantomJS來實現一個解決方案,一個Web位置打開評估和輸出保存到文件進行處理。特別是掃描惡意腳本。我已經能夠使用PhantomJS運行一次來實施解決方案。例如,這完美的作品...Phantomjs進程間通信
var system = require('system');
var page = require('webpage').create();
var lastReceived = new Date().getTime();
var requestCount = 0;
var responseCount = 0;
var requestIds = [];
var fileSystem = require('fs');
var startTime = new Date().getTime();
page.onResourceReceived = function (response) {
if(requestIds.indexOf(response.id) !== -1) {
lastReceived = new Date().getTime();
responseCount++;
requestIds[requestIds.indexOf(response.id)] = null;
}
};
page.onResourceRequested = function (request) {
if(requestIds.indexOf(request.id) === -1) {
requestIds.push(request.id);
requestCount++;
}
};
page.open('http://adserver.example.com/adserve/;ID=164857;size=300x250;setID=162909;type=iframe', function() {});
var checkComplete = function() {
// We don't allow it to take longer than 5 seconds but
// don't return until all requests are finished
if((new Date().getTime() - lastReceived > 300 && requestCount === responseCount) || new Date().getTime() - startTime > 5000) {
clearInterval(checkCompleteInterval);
console.log(page.content);
phantom.exit();
}
}
var checkCompleteInterval = setInterval(checkComplete, 1);
不過,我有巨大的困難,努力創造和自動化系統,不需要PhantomJS不斷地重新啓動它有開銷公平一點。 我嘗試使用命名管道來讀取,然後嘗試打開傳遞的url,但由於某種原因它不能正常打開。我很樂意並且非常感謝任何有關這方面的指導。
這是解決問題的精闢外側入路! –