【发布时间】:2016-02-23 03:16:00
【问题描述】:
CasperJS 很棒,但它不会将我的控制台输出内容发布到我的本地主机。
casper.wait(5000, function () {
casper.wait(1000, function () {
casper.then(function(){
for (var i = 0 ; i < 10; i++) {
var description = casper.fetchText(x('//*[@id="acDataId-local'+i+'"]/a')); //*[@id="acDataId-local0"]/a
console.log(description);
var target_date = casper.fetchText(x('//*[@id="dtDataId-local'+i+'"]/text()[1]'));
console.log(target_date);
var target_location = casper.fetchText(x('//*[@id="veDataId-local'+i+'"]'));
console.log(target_location);
console.log(i, description)
casper.then(function () {
casper.open('http://localhost:1337/events', {
method: 'post',
data: {
'description': description,
'target_date': target_date,
'target_location': target_location,
},
headers: {
"stuff":"stuff"
}
});
});
}
this.echo('POST ' + i );
});
});
});
casper.run();
Console.log 在我想要的时候准确地输出,但它只发布最后一项。我尝试在多个地方添加 casper.wait,但似乎没有帮助!
【问题讨论】:
标签: javascript loops post phantomjs casperjs