0
votes

Code:

casper.on("resource.received", function (response) {
    if (response.url.indexOf('checkcode') != -1) {
        this.log('response: ' + JSON.stringify(response), 'debug');
    }
})

Output:

[debug] [phantom] [2016-04-21T01:36:46.007Z] response: {"body":"","bodySize":1847,"contentType":"image/png","headers":[{"name":"Server","value":"Tengine/2.1.0"},{"name":"Date","value":"Thu, 21 Apr 2016 01:36:45 GMT"},{"name":"Content-Type","value":"image/png"},{"name":"Content-Length","value":"1847"},{"name":"Connection","value":"keep-alive"},{"name":"Strict-Transport-Security","value":"max-age=31536000"},{"name":"Cache-Control","value":"no-cache, private, must-revalidate"},{"name":"Pragma","value":"no-cache"},{"name":"Expires","value":"Fri, 01 Jan 1990 00:00:00 GMT"},{"name":"Set-Cookie","value":"JSESSIONID=48565DE1A6030B587CB9D14F9B53FBB4; Path=/; HttpOnly\nJSESSIONID=48565DE1A6030B587CB9D14F9B53FBB4; Path=; Secure; HttpOnly\nspanner=Kkyr7NMMCJ+YBPeL1x6AIm/qefJ/jCic4EJoL7C0n0A=;path=/;secure;"}],"id":16,"redirectURL":null,"stage":"start","status":200,"statusText":"OK","time":"2016-04-21T01:36:46.007Z","url":"https://omeo.alipay.com/service/checkcode?sessionID=94e0a91bab9e202d3ee2e574e1c8f245&t=0.6211719120304562"}

[debug] [phantom] [2016-04-21T01:36:46.011Z] response: {"contentType":"image/png","headers":[{"name":"Server","value":"Tengine/2.1.0"},{"name":"Date","value":"Thu, 21 Apr 2016 01:36:45 GMT"},{"name":"Content-Type","value":"image/png"},{"name":"Content-Length","value":"1847"},{"name":"Connection","value":"keep-alive"},{"name":"Strict-Transport-Security","value":"max-age=31536000"},{"name":"Cache-Control","value":"no-cache, private, must-revalidate"},{"name":"Pragma","value":"no-cache"},{"name":"Expires","value":"Fri, 01 Jan 1990 00:00:00 GMT"},{"name":"Set-Cookie","value":"JSESSIONID=48565DE1A6030B587CB9D14F9B53FBB4; Path=/; HttpOnly\nJSESSIONID=48565DE1A6030B587CB9D14F9B53FBB4; Path=; Secure; HttpOnly\nspanner=Kkyr7NMMCJ+YBPeL1x6AIm/qefJ/jCic4EJoL7C0n0A=;path=/;secure;"}],"id":16,"redirectURL":null,"stage":"end","status":200,"statusText":"OK","time":"2016-04-21T01:36:46.010Z","url":"https://omeo.alipay.com/service/checkcode?sessionID=94e0a91bab9e202d3ee2e574e1c8f245&t=0.6211719120304562"}

And I got those logs, but there is no binary in the response, so I can't get the image...

So, how to get the binary of the image requested by CasperJS?

1
The response content is not available in PhantomJS. Since you have the URL, have you tried to casper.download(...) it?Artjom B.
@ArtjomB. The url returns different image for every request(a CAPTCHA indeed). So if I download it, it's not the CAPTCHA image displayed in the PhantomJS.Sayakiss
@ArtjomB. But I find a hack, this.captureBase64('png', '#J-checkcode-img'), that works...Sayakiss
Just run the script with the --web-security=false commandline option and CORS will be disabledArtjom B.

1 Answers

0
votes

As ArtjomB commented:

The response content is not available in PhantomJS

So I hack it by this.captureBase64('png', '#J-checkcode-img').