HtmlImage image = page.<HtmlImage>getFirstByXPath("//img[@src='blah']"); File imageFile = new File("/path/to/file.jpg"); image.saveAs(imageFile);
File fileToSaveImage = new File(dirToSave, normalizedName); HtmlImage elementHtmlImage = (HtmlImage) pageWithImage.<HtmlImage>getFirstByXPath(X_PATH_FOR_IMAGE); elementHtmlImage.saveAs(fileToSaveImage);
protected Map<String, DomAttr> getAttributesFor(final HtmlImage image) { final Map<String, DomAttr> map = new HashMap<String, DomAttr>(image.getAttributesMap()); final String src = map.get("src").getValue(); try { final ImageReader reader = image.getImageReader(); final File file = createFile(src, "." + reader.getFormatName()); image.saveAs(file); outputDir_.mkdirs(); map.get("src").setValue(outputDir_.getName() + File.separatorChar + file.getName()); } catch (final Exception e) { throw new RuntimeException(e); } return map; }
protected Map<String, DomAttr> getAttributesFor(final HtmlImage image) { final Map<String, DomAttr> map = new HashMap<String, DomAttr>(image.getAttributesMap()); final String src = map.get("src").getValue(); try { final ImageReader reader = image.getImageReader(); final File file = createFile(src, "." + reader.getFormatName()); image.saveAs(file); outputDir_.mkdirs(); map.get("src").setValue(outputDir_.getName() + File.separatorChar + file.getName()); } catch (final Exception e) { throw new RuntimeException(e); } return map; }
protected Map<String, DomAttr> getAttributesFor(final HtmlImage image) { final Map<String, DomAttr> map = new HashMap<String, DomAttr>(image.getAttributesMap()); final String src = map.get("src").getValue(); try { final ImageReader reader = image.getImageReader(); final File file = createFile(src, "." + reader.getFormatName()); image.saveAs(file); outputDir_.mkdirs(); map.get("src").setValue(outputDir_.getName() + File.separatorChar + file.getName()); } catch (final Exception e) { throw new RuntimeException(e); } return map; }