CasperJS在没有其他无用数据的情况下无法获得IP



我现在已经更新了CasperJS脚本,如下所示

var casper = require('casper').create();
casper.start('http://whatismyipaddress.com/', function() {
    if (this.exists('#section_left > div:nth-child(2)')) {
        var data = this.getElementInfo('#section_left > div:nth-child(2)');
        console.log(JSON.stringify(data.text));
    }
});
casper.run();

如何从下面得到的结果中删除"nt

"nn23.221.147.202nnttttt"
data.text是一个

字符串。字符串化会导致转义空格和添加引号。不要字符串化:

console.log(data.text);

如果你真的想删除空格,有字符串函数trim()

console.log(data.text.trim());

相关内容

最新更新