我想知道,如何使用selenium / webdriver下载页面的图像。假设需要用户 session 来下载图像,因此具有纯URL并没有帮助。任何示例代码都受到高度赞赏。
最佳答案
我喜欢做这样的事情:
1. Get the SRC attribute of the image.
2. Use ImageIO.read to read the image onto a BufferedImage
3. Save the BufferedImage using ImageIO.write function
例如
String src = imgElement.getAttribute('src');
BufferedImage bufferedImage = ImageIO.read(new URL(src));
File outputfile = new File("saved.png");
ImageIO.write(bufferedImage, "png", outputfile);
关于selenium - 如何使用Selenium(任何版本)下载图像?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6813704/