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
Question
Here is my script from 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?
Solution
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
OTHER TIPS
Try using this:
this.echo(this.getElementAttribute('img#cpt_img', 'src'));