所以我有2个地址,它们返回json对象链接a
返回AAAA
,链接b
返回BBBB
链接b
有点复杂....基本上,casper应当继续调用链接b,直到设置了正确的值,并且从链接b返回正确的数据为止。这就是为什么我在{{1}内调用链接b的原因。 }
无论如何,问题是当我调用链接waitFor
并casper.log它的内容时,它仍然为我提供链接b
的内容
这是我的代码
a
这是日志
casper2.start('http://localhost/skywin/client/charg/link/a' , function(){
casper2.log('----------------------------LINK A ------------------------------]]]]]]', 'debug');
casper2.log(this.getPageContent() , 'debug');
})
.waitFor(function check(){
casper2.log('----------------------------LINK B------------------------------->>>>>>>', 'debug');
var xdata = this.open('http://localhost/skywin/client/charg/link/b').getPageContent();
casper2.log( (xdata) , 'warning');
try {
var rdata = JSON.parse(xdata) ;
} catch (e) {
return false;
}
return rdata.stat == 'BBBBBBB' ? true : false ;
})
.run(function(){
this.echo("DONE 2");
});
您可以看到我有
[info] [phantom] Step anonymous 2/3 http://localhost/skywin/client/charg/link/a (HTTP 200)
[debug] [phantom] ----------------------------LINK A ------------------------------]]]]]]
[debug] [phantom] {"stat":"AAAAAAA"}
[info] [phantom] Step anonymous 2/3: done in 726ms.
[info] [phantom] Step _step 3/3 http://localhost/skywin/client/charg/link/a (HTTP 200)
[info] [phantom] Step _step 3/3: done in 741ms.
[debug] [phantom] ----------------------------LINK B------------------------------->>>>>>>
[debug] [phantom] opening url: http://localhost/skywin/client/charg/link/b, HTTP GET
[debug] [phantom] Navigation requested: url=http://localhost/skywin/client/charg/link/b, type=Other, willNavigate=true, isMainFrame=true
[warning] [phantom] {"stat":"AAAAAAA"}
[debug] [phantom] ----------------------------LINK B------------------------------->>>>>>>
[debug] [phantom] opening url: http://localhost/skywin/client/charg/link/b, HTTP GET
[debug] [phantom] Navigation requested: url=http://localhost/skywin/client/charg/link/b, type=Other, willNavigate=true, isMainFrame=true
[warning] [phantom] <html><head></head><body style=""><pre style="word-wrap: break-word; white-space: pre-wrap;">{"stat":"AAAAAAA"}</pre></body></html>
[warning] [phantom] Loading resource failed with status=fail: http://localhost/skywin/client/charg/link/b
[debug] [phantom] Automatically injected jquery.js client side
它只是不断返回链接[debug] [phantom] ----------------------------LINK B------------------------------->>>>>>>
[warning] [phantom] {"stat":"AAAAAAA"}
[debug] [phantom] ----------------------------LINK B------------------------------->>>>>>>
[warning] [phantom] <html><head></head><body style=""><pre style="word-wrap: break-word; white-space: pre-wrap;">{"stat":"AAAAAAA"}</pre></body></html>
[warning] [phantom] Loading resource failed with status=fail: http://localhost/skywin/client/charg/link/b
的内容我缺少什么吗?
btw我在浏览器中尝试了链接b,它返回了正确的值