[英]I have a CasperJS script that outputs a string, how can I trim the text
这是我来自CasperJS的脚本:
var casper = require('casper').create();
var url = 'https://example.wsw/';
casper.start('https://example.wsw/login.html', function() {
//this.echo(this.getTitle());
//this.download(url, 'google_company.html');
this.echo(this.getHTML('img#cpt_img', true));
});
casper.run();
我从中得到的输出是:
<img id="cpt_img" src="/user/turing/image.asp?1394574424">
这就是我想要得到的输出:
/user/turing/image.asp?1394574424
因此以后可以在需要时在上方使用此字符串。
谁能显示我将字符串更改为我在输出中所需的字符串?
您可以尝试以下方法:
var imgTag = this.getHTML('img#cpt_img', true);
var src = imgTag.match(/src="(.*?)"/)[1];
尝试使用此:
this.echo(this.getElementAttribute('img#cpt_img', 'src'));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.