c#、cefsharp 获取、提取 img、image 图片标签二进制数据

主要是为了用cef做自动登录时打码用,但是又不想通过拦截response,因为那样太不够直观。

标签内容为:

<img src="Image.do?_timesShow=2&amp;ran=100509925" title="点击更换图片!" alt="" class="sz" onclick="this.src='Image.xx?ran='+Math.random()" style="padding-top:4px;padding-left:10px;">

图片显示为链接,百度了一圈,也有一些写了提取方法的,但是比较模糊,记录一下。

以下js代码为,直接执行返回即为base64图片数据,在c#里解为byte[]就可以上传打码了。

至于c#如何让cefsharp执行js就简单了、browser.GetMainFrame().EvaluateScriptAsync(jscode)

            (function() {
    var getDataFromImg = function(img) {
        var canvas = document.createElement('canvas');
        var context = canvas.getContext('2d'); 
canvas.width = 90; //验证码长
    canvas.height = 22;//验证码宽
        context.drawImage(img, 0, 0 );
        var dataURL = canvas.toDataURL('image/png');

        return dataURL.replace(/^data:image\/(png|jpg);base64,/, '');
    }
//获取图片标签,在开发工具选中img标签,右键copy -> copy js xpath
var img = document.querySelector("#loginrtModule > div.module2 > div.module4 > div > p.verify_code > img")
    return getDataFromImg(img );
})();
"iVBORw0KGgoAAAANSUhEUgAAAFoAAAAWCAYAAABAMosVAAAGuElEQVRoQ+2Z104jTRCF2xiTcw4CARe8/6sgcYVE1Iqcc3D49Y39zRYDa7za/a/Ylrw2Pd0VTp2uqp4tpZQao6Oj6ebmJpVKpdRoNFJ/f396enpKPT096fX1NZsfGRlJt7e32fO+vr70/PycOhnKYK2/u7q6Ur1eTwMDA+nx8TGXzfNqtZo90xZ1DA0Npfv7+1SpVLKpt7e3d+r1AdnIZa16WOhv/Hh4eEi1Wu3d/nK5nAYHBzMf4z4WoRN9xW+edXd3Zzb7zL95hsxarVbid2l0dLSxvb2dJicncweiM/xGuYIwFMEAgaCvBg65DgcxpLe39902gol8AI4yCTZBj8C/vLxkAQMMbCDgBP7o6CjNz89ncrEXOx3IZw+D/ejHFoBl+NtnzMU92IFdfj6Tjz345j4IyRwY+0+DSQBhkUYMDw9nRlxeXqaJiYncaBxj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BqP1pcF/MsgHLkcMI8StAApx2jY+8s2wg+oBRZGO0zFZnnCay3RtdhO/pji2o6tIgCMF2KRRhS4ocn2BYTWd5skcEeLlB510Ex/Cp1yGKEEnHYiSFEFKEYSvRkTQQHp2Je83Jkd9Mpoy3UXqBgNzag24LNN2zmBMbTwTx6AYMPtsJmawQFmvaONBIvTcUiH1MWvkY2e6s1cHy3fOs8ddjamYMsct70ZGTsVc3PMoPjDbheoQEf8HC8kxztMY7O2noKKvbw8T1GrC3Mo58gYBt5HJtYa7DjLdbTJmOx0Q7J1wXaTeD+GGic4KgADIKt8hYBjgtXaG9bFkzW6ijM4RhRuGjtYp9pD+ycQMbLBmtksh0BsjhdBABb4imCEOwxZ9sFsBZfIA7yscvfFnLkeJEyVclsTg9MtqhKOOvOH6UO2zpbJITPzc1lfauKvKYS6ZinYzGxWsfjGNPGr4D23QNrdcRi48stmQjAzAGaL5EEK3YxMDO+KbRrKLar6DbF4Zcvs/QFTJD/14qhgBJN8zlGaFgRUOZNI7F/JfI6aRfTSY42OLZt0UGeRebFdyt2NsW2UKAi2Ngcb5vxkhJl2gWR9uw+OmrvmneK5mVBFvguupPXoMWC8R3/9s0nzQFDLN+1d/FdhzchNsQXKt8RvE59lox2X95Y2d9qAJpdR6VSaWxtbaWVlZUPsj97ydOpAd9l3a8w2tvbS+vr66Tan+86VldX0+7ubo7N7/xX1XcB9Cs/i5gFTHOgv5Lx7/lfQKD5Zvvf+N8R+A/am+xxifiY0AAAAABJRU5ErkJggg=="

 

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值