如何获取Casperjs请求的图像的二进制文件?[英] How to get the binary of the image requested by CasperJS?

问题描述

代码:

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

输出:

[debug] [phantom] [2016-04-21T01:36:46.0​​07Z]响应: {" Body":""," Bodysize":1847," contentType":" Image/png"," headers":[{" name":" server"," value":" tengine/2.1.0"} ,{" name":" date"," value":" thu, 2016年4月21日01:36:45 gmt"},{" name":" content-type"," value":" image/png"},{" name":" content-Length"," value"," value":" 1847"},{" name" :"连接"," value":" keep-alive"},{" name":" strict-transport-security"," value":" max-age = 31536000"},{" name":" cache--控制"," value":"无循环, 私人的, 必须重新定位"},{" name":" pragma"," value":" no-cache"},{" name":" expires"," value":" fri,fri,fri,fri, 1990年1月1日00:00:00 gmt"},{" name":" set-cookie"," value":" jsessionId = 48565DE1A6030B587CB9D14F9B53FBB4; 路径=/; httponly \ njSessionID = 48565DE1A6030B587CB9D14F9B53FBB4;路径=; 安全的; HttpOnly\nspanner=Kkyr7NMMCJ+YBPeL1x6AIm/qefJ/jCic4EJoL7C0n0A=;path=/;secure;"}],"id":16,"redirectURL":null,"stage":"start","status":200," statustext":" ok"," time":" 2016-04-21T01:36:46.0​​07Z"," url":" https://omeo.alipay.com/service/checkcode?sessionID=94e0a91bab9e202d3ee2e574e1c8f245&t=0.6211719120304562"}

[debug] [phantom] [2016-04-21T01:36:46.0​​11Z]响应: {" contentType":" image/png"," headers":[{" name":" server"," value":" tengine/2.1.0"},{" name":" date":" date"," value"," value" :" thu, 2016年4月21日01:36:45 gmt"},{" name":" content-type"," value":" image/png"},{" name":" content-Length"," value"," value":" 1847"},{" name" :"连接"," value":" keep-alive"},{" name":" strict-transport-security"," value":" max-age = 31536000"},{" name":" cache--控制"," value":"无循环, 私人的, 必须重新定位"},{" name":" pragma"," value":" no-cache"},{" name":" expires"," value":" fri,fri,fri,fri, 1990年1月1日00:00:00 gmt"},{" name":" set-cookie"," value":" jsessionId = 48565DE1A6030B587CB9D14F9B53FBB4; 路径=/; httponly \ njSessionID = 48565DE1A6030B587CB9D14F9B53FBB4;路径=; 安全的; HttpOnly\nspanner=Kkyr7NMMCJ+YBPeL1x6AIm/qefJ/jCic4EJoL7C0n0A=;path=/;secure;"}],"id":16,"redirectURL":null,"stage":"end","status":200," statustext":" ok"," time":" 2016-04-21T01:36:46.0​​10Z"," url":" https://omeo.alipay.com/service/checkcode?sessionID=94e0a91bab9e202d3ee2e574e1c8f245&t=0.6211719120304562"}

我得到了那些日志,但是响应中没有二进制文件,所以我无法获得图像...

那么,如何获取Casperjs请求的图像的二进制?

推荐答案

Artjomb评论:

phantomjs

中没有响应内容

所以我通过this.captureBase64('png', '#J-checkcode-img').

入侵它

本文地址:https://www.itbaoku.cn/post/1740150.html