我需要从ajax加载的页面中获取项目(带选择器[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减少这个时间,或者我需要使用其他工具吗?
答案 0 :(得分:0)
在某些站点上,我发现这对Phantom JS的加载时间有利。 在其他站点上,图像仍然出现,并且没有区别。
page.settings.loadImages = false;