0
爲什麼在'clickOldShares'中等待不起作用?即使我在裏面評價,等待也不起作用。我相信這是一個帶有參考的小細節,但我現在沒有想法。在CasperJS你如何做等待工作?
function clickOldShares(){
console.log("Waiting for Old Shares");
element = document.querySelector("#pagelet_scrolling_pager > div > div > a");
console.log("ELEMENT: " + element);
if(element){
console.log('click and waiting...');
element.click();
console.log('clicked!'+ element);
//THIS WAIT IS NOT WORKING!!!! I DON'T KNOW WHY!!!!
this.wait(2000,clickOldShares);
}
else {
console.log("done!");
}
return element;
};
//Initializing Casper
casper.start('https://www.facebook.com/', function() {
console.log("Entering on Facebook");
});
//Remote Message Handler - now I can see what happen inside evaluates
casper.on('remote.message', function(msg) {
this.echo(msg);
})
//Facebook login
casper.then(function(){
console.log("Login using username and password");
this.evaluate(function(){
document.getElementById("email").value = '[email protected]';
document.getElementById("pass").value = 'somepass';
document.getElementById("login_form").submit();
})
if(this.exists('#u_0_2 > div:nth-child(1) > div:nth-child(1) > div > a > span')){
console.log("Login ok!");
}
else {
console.log("Login not ok!");
casper.exit();
}
});
casper.thenOpen("https://www.facebook.com/shares/view?id=1063249230414580" ,function(){
console.log("Open post with object-id");
});
casper.thenClick("#pagelet_scrolling_pager > div > div > a",function(){
this.wait(2000,function(){ this.evaluate(clickOldShares)});
});
我太親近了!但是,多虧了你,我更瞭解了JavaScript中的'範圍遊戲'。非常感謝! 圖像不好,因爲有很多數據。但是我已經要求getHTML來查看,並且所有內容都在那裏! 我欠你一杯啤酒! 再次感謝! :D –
'!!元素'呢?我不知道這在JavaScript中。有關於它的文檔?說到這一點,我可以問你一篇關於Javascript文章的建議嗎? –
[這個符號在JavaScript中的含義是什麼?](http://stackoverflow.com/q/9549780/1816580)參考問題鏈接到[什麼是! (不是)運營商在JavaScript?](http://stackoverflow.com/q/784929/1816580),這是需要在這裏,因爲DOM節點不能被傳遞出的頁面上下文。這個限制是PhantomJS的一個特點,並不是由於JavaScript。 –