casperjs评估函数无法返回我需要的数据

casperjs evaluate function cannot return data i need

本文关键字:数据 返回 评估 函数 casperjs      更新时间:2023-09-26

无法使我的函数正确返回数据我想获取这个输入框的值

<input type="text" value="example@outlook.com" maxlength="100" size="40" name="mail"></input> 

所以我构建了一个类似so 的函数

exports.Details = function() {
casper.thenOpen("https://perfectmoney.is/settings.html", function() { 
var fetch = casper.fetchText('#reg > table:nth-child(3) > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(1) > table:nth-child(4) > tbody:nth-child(1) > tr:nth-child(8) > td:nth-child(2) > input:nth-child(1)')
});
};

然后我像这样调用我的函数

casper.then(function() {
var item = pief.Details();
console.log(item);
});

我得到的结果是不确定的,我如何修复这个

casper.then(function(){
     value = this.evaluate(function() {
         return __utils__.findOne('input').getAttribute('value');
     });
});
casper.then(function(){
    this.echo(value);
});

我建议您为此输入添加一个id。并通过input#id_name. 进行搜索