我现在已经更新了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();
如何从下面得到的结果中删除"
和n
和t
。
"nn23.221.147.202nnttttt"
data.text
是一个字符串。字符串化会导致转义空格和添加引号。不要字符串化:
console.log(data.text);
如果你真的想删除空格,有字符串函数trim()
:
console.log(data.text.trim());