如何抓取canvas画布中的图片

如何抓取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);
}

在这里插入图片描述
作者:香芋味的猫丶

猜你喜欢

转载自blog.csdn.net/weixin_49701447/article/details/111225016