尝试使用casperjslogin到网站。 提交表单会产生一个ajax请求

捕获的结果给了我一个login页面的图片,它带有一个正在进行的gif,它没有显示仪表盘的图片,或者是什么login后的页面,这是我想要的。 我尝试使用所有types的waitfor(),但我失败了。

var casper = require("casper").create({ userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.172 Safari/537.22', pageSettings : { userAgent : "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.157 Safari/537.36" }, verbose : true, logLevel : "debug", clientScripts : ["jquery.js"] }) var fs = require("fs"); casper.on("error", function(msg){ this.echo("error: " + msg, "Error"); }) casper.on("page.error", function(msg, trace){ this.echo("Page Error: " + msg, "error"); }); var alexa = "https://www.alexa.com/secure/login?resource=%2Fpro%2Fscreener"; var proScreener = "http://www.alexa.com/pro/screener" var form = "form#ajax-login-form"; var submitButton = "input#submit"; casper.start(alexa, function(){ casper.waitForSelector(form, function(){ // var cookies = JSON.stringify(phantom.cookies); // fs.write("cookies.txt", cookies, 644); console.log("form found!!"); }) }); casper.then(function(){ casper.sendKeys('input[id="email"]', "hiding.com"); casper.sendKeys('input[id="pwd"]', "hidingPass"); casper.click(submitButton); }) casper.then(function(){ this.capture("Afterlogin.png"); // this.waitFor(function check(){ // return this.evaluate(function(){ // return document.querySelectorAll(".profile.popped").length // }); // }, function then(){ // this.captureSelector("selector.png",".profile.popped" ) // }) }) 

在命令promp中:

 [info] [phantom] Step _step 3/5: done in 36592ms. [info] [phantom] waitFor() finished in 40ms. [info] [phantom] Step anonymous 4/6 https://www.alexa.com/secure/login?resource= /pro/screener (HTTP 200) form found!! [info] [phantom] Step anonymous 4/6: done in 36666ms. [info] [phantom] Step anonymous 5/6 https://www.alexa.com/secure/login?resource= /pro/screener (HTTP 200) [debug] [phantom] Mouse event 'mousedown' on selector: input[id="email"] [debug] [phantom] Mouse event 'mouseup' on selector: input[id="email"] [debug] [phantom] Mouse event 'click' on selector: input[id="email"] [debug] [phantom] Mouse event 'mousedown' on selector: input[id="pwd"] [debug] [phantom] Mouse event 'mouseup' on selector: input[id="pwd"] [debug] [phantom] Mouse event 'click' on selector: input[id="pwd"] [debug] [phantom] Mouse event 'mousedown' on selector: input#submit [debug] [phantom] Mouse event 'mouseup' on selector: input#submit [debug] [phantom] Mouse event 'click' on selector: input#submit [info] [phantom] Step anonymous 5/6: done in 36844ms. [info] [phantom] Step anonymous 6/6 https://www.alexa.com/secure/login?resource= /pro/screener (HTTP 200) [debug] [phantom] Capturing page to C:/Users/jack/Desktop/node-working/casperpra c3/Afterlogin.png [info] [phantom] Capture saved to C:/Users/jack/Desktop/node-working/casperprac3 /Afterlogin.png [info] [phantom] Step anonymous 6/6: done in 36994ms. [info] [phantom] Done 6 steps in 36999ms [debug] [phantom] Navigation requested: url=about:blank, type=Other, willNavigat e=true, isMainFrame=true [debug] [phantom] url changed to "about:blank"