感谢有人可以帮我解决这个问题。
请参阅我的图片以进一步了解。
https://onedrive.live.com/redir?resid=F95DD828CA2E63D7!1326&authkey=!AEbavlKl38fBJYI&v=3&ithint=photo%2cjpg
我有一个实际的CasperJS html捕获截图。它显示casperjs正确进入谷歌领域。问题是
var casper = require('casper')。create({ 详细说明:是的, logLevel:'debug', pageSettings:{ userAgent:'Mozilla / 5.0(Windows NT 6.1)AppleWebKit / 537.36(KHTML,如Gecko)Chrome / 41.0.2228.0 Safari / 537.36' } });
var url = 'http://www.google.com/';
var fs = require('fs');
var links = [];
function getLinks() {
var links = document.querySelectorAll('h3.r a');
this.echo('Getting links now-----------------------------------------')
return Array.prototype.map.call(link, function(e) {
return e.innerText;
});
}
casper.start(url, function() {});
casper.then(function() {
this.fillSelectors('form#tsf', {
'input[name="q"]': 'Funny Man'
}, true);
this.echo('\n Filling is complete...');
})
casper.then(function() {
this.mouseEvent('click', 'input[name="btnK"]');
this.echo('Mouse Event Done...');
casper.capture('screenshot/google_search0.png');
});
casper.then(function() {
this.mouseEvent('click','button[name="btnG"]' );
this.echo('***************************************Done');
casper.capture('screenshot/google_search1.png');
});
casper.waitFor(function check() {
return this.evaluate(function() {
return document.querySelectorAll('#resultStats').length >= 1;
});
}, function then() { // step to execute when check() is ok
casper.capture('screenshot/google_search2.png');
links = this.evaluate(getLinks);
console.log('BOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOyeahhhhhhhh')
}, function timeout() { // step to execute if check has failed
casper.capture('screenshot/google_search3.png');
this.echo('search page load has failed. go see why********************');
});
casper.then(function() {
this.echo('++++++++++++++++++++++++++++++++++++++++++++++++++');
links = this.evaluate(getLinks);
});
casper.run(function() {
this.echo('Capturing screenshot...');
casper.capture('screenshot/google2.png');
fs.write('outputs/google_results4.html', this.getHTML(), 'w');
this.echo(links);
casper.exit();
});
非常感谢。