PhantomJS 脚本太慢


Too slow PhantomJS script

我需要从ajax加载的页面中获取项目(使用选择器a[id=test])。为此,我使用phantomjs。

在 PHP 中:

$phantom_path = '/usr/bin/phantomjs';
$names  = shell_exec("$phantom_path model/phantomscript-names.js $url");

在PhantomJS中,我收到了物品:

var page = require('webpage').create(),
    system = require('system'),
    url = system.args[1];
page.open(url, function(status) {
    page.injectJs('jquery-2.1.4.min.js');
    var links = page.evaluate(function() {
        return [].map.call(document.querySelectorAll('a[id=test]'), function(link) {
            return link.innerText;
        });
    });
    console.log(links.join(''n'));
    phantom.exit();
});

脚本为每个页面运行大约一分钟。是否可以使用 PhantomJS 减少此时间,或者我需要为此使用其他工具?

在某些网站上,我发现这有利于Phantom JS的加载时间。在其他网站上,图像仍然会出现,没有区别。

page.settings.loadImages = false;