How to get the binary of the image requested by CasperJS?

点点圈 提交于 2020-01-06 14:46:35

问题


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:


As ArtjomB commented:

The response content is not available in PhantomJS

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



来源:https://stackoverflow.com/questions/36758093/how-to-get-the-binary-of-the-image-requested-by-casperjs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!