[英]I have a CasperJS script that outputs a string, how can I trim the text
Here is my script from CasperJS: 这是我来自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();
The out put I get from this is: 我从中得到的输出是:
<img id="cpt_img" src="/user/turing/image.asp?1394574424">
and this is what I am trying to get it the output: 这就是我想要得到的输出:
/user/turing/image.asp?1394574424
so I can use this string above later when I need it. 因此以后可以在需要时在上方使用此字符串。
Can anyone show me away to change the string to what I need in the output? 谁能显示我将字符串更改为我在输出中所需的字符串?
You can try this: 您可以尝试以下方法:
var imgTag = this.getHTML('img#cpt_img', true);
var src = imgTag.match(/src="(.*?)"/)[1];
Modified from https://stackoverflow.com/a/1684206/3351720 从https://stackoverflow.com/a/1684206/3351720修改
尝试使用此:
this.echo(this.getElementAttribute('img#cpt_img', 'src'));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.