如何抓取canvas画布中的图片
网络页面中存放图片的形式有很多
这里说一下canvas
格式时怎么获取
String fullImgJs = "return document.getElementsByClassName(\"元素className\")[0].children[0].toDataURL(\"image/png\");";
String imgFilePath = "c://img.png";
String imgInfo = ((JavascriptExecutor) driver).executeScript(fullImgJs).toString();
if (imgInfo != null && imgInfo.contains("data")) {
imgInfo = imgInfo.substring(imgInfo.indexOf(",") + 1);
byte[] data = new BASE64Decoder().decodeBuffer(imgInfo);
FileUtils.writeByteArrayToFile(new File(imgFilePath), data);
}
作者:香芋味的猫丶