Refine search
public Main() throws Exception { WebClient webClient = new WebClient(); webClient.setJavaScriptEnabled(false); HtmlPage page = webClient.getPage("http://www.chapitre.com"); List<HtmlImage> imageList = (List<HtmlImage>) page.getByXPath("//img"); for (HtmlImage image : imageList) { try { new URL(image.getSrcAttribute()); if (image.getHeightAttribute().equals("1") && image.getWidthAttribute().equals("1")) { System.out.println(image.getSrcAttribute()); } } catch (Exception e) { System.out.println("You didn't see this comming :)"); } } }
public ControlsTypeHere PrintImages(int take, int skip) { int filesPrinted; for (int i = skip; i < Files.Count; i++) { if(filesPrinted >= take) break; HtmlImage image=new HtmlImage(); image.ID="ImageAN"+i.ToString(); image.Src=Files[i].ToString(); image.Alt="PrintImage"; image.Attributes.Add("class","PrintImage"); div_Print.Controls.Add(image); filesPrinted++; } return div_Print.Controls; }
/** * Simulates clicking this element at the position <tt>(0, 0)</tt>. This method returns * the page contained by this image's window after the click, which may or may not be the * same as the original page, depending on JavaScript event handlers, etc. * * @return the page contained by this image's window after the click * @exception IOException if an IO error occurs */ @Override @SuppressWarnings("unchecked") public Page click() throws IOException { return click(0, 0); }
/** * @return true if the image was successfully downloaded */ public boolean isComplete() { return isComplete_ || (hasFeature(JS_IMAGE_COMPLETE_RETURNS_TRUE_FOR_NO_REQUEST) ? ATTRIBUTE_NOT_DEFINED == getSrcAttribute() : imageData_ != null); }
/** * Makes sure that all the images in the page loads successfully. * (By default, HtmlUnit doesn't load images.) */ public void assertAllImageLoadSuccessfully(HtmlPage p) { for (HtmlImage img : DomNodeUtil.<HtmlImage>selectNodes(p, "//IMG")) { try { img.getHeight(); } catch (IOException e) { throw new Error("Failed to load "+img.getSrcAttribute(),e); } } }
if (getUseMapAttribute() != ATTRIBUTE_NOT_DEFINED) { final String mapName = getUseMapAttribute().substring(1); final HtmlElement doc = ((HtmlPage) getPage()).getDocumentElement(); final HtmlMap map = doc.getOneHtmlElementByAttribute("map", "name", mapName); for (final DomElement element : map.getChildElements()) { final HtmlAnchor anchor = (HtmlAnchor) getEnclosingElement("a"); if (anchor == null) { return false; if (getIsmapAttribute() != ATTRIBUTE_NOT_DEFINED) { final String suffix = "?" + lastClickX_ + "," + lastClickY_; anchor.doClickStateUpdate(false, false, suffix);
/** * <span style="color:red">POTENIAL PERFORMANCE KILLER - DOWNLOADS THE IMAGE - USE AT YOUR OWN RISK.</span><br/> * If the image is not already downloaded it triggers a download. Then it stores the image in the HtmlImage * object for later use.<br/> * * Downloads the image specified in the src attribute. * * @throws IOException if an error occurs while downloading the image or if the stream is of an * unsupported content-type */ private void downloadImageIfNeeded() throws IOException { if (!downloaded_) { final HtmlPage page = (HtmlPage) getPage(); final WebClient webclient = page.getWebClient(); final URL url = page.getFullyQualifiedUrl(getSrcAttribute()); final WebRequestSettings request = new WebRequestSettings(url); request.setAdditionalHeader("Referer", page.getWebResponse().getRequestSettings().getUrl().toExternalForm()); imageWebResponse_ = webclient.loadWebResponse(request); downloaded_ = true; } }
if (!downloaded_) { final String src = getSrcAttribute(); if (!"".equals(src) && !(hasFeature(HTMLIMAGE_BLANK_SRC_AS_EMPTY) && StringUtils.isBlank(src))) { final HtmlPage page = (HtmlPage) getPage(); final WebClient webclient = page.getWebClient(); final URL url = page.getFullyQualifiedUrl(src); final String accept = webclient.getBrowserVersion().getImgAcceptHeader(); final WebRequest request = new WebRequest(url, accept); request.setCharset(page.getCharset()); request.setAdditionalHeader(HttpHeader.REFERER, page.getUrl().toExternalForm()); imageWebResponse_ = webclient.loadWebResponse(request); isComplete_ = hasFeature(JS_IMAGE_COMPLETE_RETURNS_TRUE_FOR_NO_REQUEST) || (imageWebResponse_ != null && imageWebResponse_.getContentType().contains("image"));
if (!(getPage() instanceof HtmlPage)) { return; // nothing to do if embedded in XML code final HtmlPage htmlPage = (HtmlPage) getPage(); final Function onload = getEventHandler("onload"); if (onload != null) { downloadImageIfNeeded(); final int i = imageWebResponse_.getStatusCode(); ok = (i >= SC_OK && i < SC_MULTIPLE_CHOICES) || i == SC_USE_PROXY; final Node scriptObject = (Node) getScriptObject(); final PostponedAction action = new PostponedAction() { public void execute() throws Exception { final String readyState = htmlPage.getReadyState(); if (READY_STATE_LOADING.equals(readyState)) { htmlPage.addAfterLoadAction(action); htmlPage.getWebClient().getJavaScriptEngine().addPostponedAction(action);
final HtmlPage htmlPage = getHtmlPageOrNull(); if (htmlPage == null) { return; // nothing to do if embedded in XML code final WebClient client = htmlPage.getWebClient(); if (!client.getOptions().isJavaScriptEnabled()) { onloadProcessed_ = true; if ((hasEventHandlers("onload") || hasEventHandlers("onerror")) && hasAttribute("src")) { onloadProcessed_ = true; boolean loadSuccessful = false; if (!getSrcAttribute().isEmpty()) { downloadImageIfNeeded(); final int i = imageWebResponse_.getStatusCode(); if (READY_STATE_LOADING.equals(htmlPage.getReadyState())) { final PostponedAction action = new PostponedAction(getPage()) { @Override public void execute() throws Exception { htmlPage.addAfterLoadAction(action); fireEvent(event);
/** * Returns the value of the <tt>src</tt> attribute. * @return the value of the <tt>src</tt> attribute */ public String jsxGet_src() { final HtmlImage img = (HtmlImage) getDomNodeOrDie(); final String src = img.getSrcAttribute(); if (instantiatedViaJavaScript_ && "".equals(src)) { return src; } try { final HtmlPage page = (HtmlPage) img.getPage(); return page.getFullyQualifiedUrl(src).toExternalForm(); } catch (final MalformedURLException e) { final String msg = "Unable to create fully qualified URL for src attribute of image " + e.getMessage(); throw Context.reportRuntimeError(msg); } }
private HtmlImage findReferencingImage() { final HtmlPage page = getHtmlPageOrNull(); String name = getNameAttribute(); if (null != page && StringUtils.isNotBlank(name)) { name = "#" + name.trim(); for (HtmlElement elem : page.getDocumentElement().getElementsByTagName("img")) { final HtmlImage image = (HtmlImage) elem; if (name.equals(image.getUseMapAttribute())) { return image; } } } return null; } }
final boolean notifyAttributeChangeListeners, final boolean notifyMutationObservers) { final HtmlPage htmlPage = getHtmlPageOrNull(); if ("src".equals(qualifiedName) && value != ATTRIBUTE_NOT_DEFINED && htmlPage != null) { final String oldValue = getAttributeNS(namespaceURI, qualifiedName); if (!oldValue.equals(value)) { super.setAttributeNS(namespaceURI, qualifiedName, value, notifyAttributeChangeListeners, final String readyState = htmlPage.getReadyState(); if (READY_STATE_LOADING.equals(readyState)) { final PostponedAction action = new PostponedAction(getPage()) { @Override public void execute() throws Exception { htmlPage.addAfterLoadAction(action); return; doOnLoad(); return;
import java.net.URL; import java.util.List; import com.gargoylesoftware.htmlunit.WebClient; import com.gargoylesoftware.htmlunit.html.HtmlImage; import com.gargoylesoftware.htmlunit.html.HtmlPage; public class urlscrap { public static void main(String[] args) throws Exception { //WebClient webClient = new WebClient(Opera); WebClient webClient = new WebClient(); HtmlPage currentPage = (HtmlPage) webClient.getPage(new URL("http://www.google.com")); //get list of all divs final List<?> images = currentPage.getByXPath("//img"); for (Object imageObject : images) { HtmlImage image = (HtmlImage) imageObject; System.out.println(image.getSrcAttribute()); } //webClient.closeAllWindows(); } }
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; }
if(input.getSrcAttribute().equalsIgnoreCase("customize.gif") ) String result = page2.asText(); try { BufferedWriter out = new BufferedWriter(new FileWriter("Filepath\\"+customer+i+".txt"));
HtmlElement element4 = null; Iterable<HtmlElement> iterable5 = page.getAllHtmlChildElements(); Iterator<HtmlElement> i6 = iterable5.iterator(); while(i6.hasNext() { HtmlElement anElement = i6.next(); if(anElement instanceof HtmlImage) { HtmlImage input = (HtmlImage) anElement; String[] elements = "http://example.com/pages/powerbutton.png".split( "/" ); if(input.getSrcAttribute().indexOf(elements[elements.length-1] )> -1 ){ element4 = input; break; } } } HtmlPage page = element4.click();
/** * Saves this image as the specified file. * @param file the file to save to * @throws IOException if an IO error occurs */ public void saveAs(final File file) throws IOException { final ImageReader reader = getImageReader(); ImageIO.write(reader.read(0), reader.getFormatName(), file); } }
private void readImageIfNeeded() throws IOException { downloadImageIfNeeded(); if (imageData_ == null) { if (null == imageWebResponse_) { throw new IOException("No image response available (src=" + getSrcAttribute() + ")"); } @SuppressWarnings("resource") final ImageInputStream iis = ImageIO.createImageInputStream(imageWebResponse_.getContentAsStream()); final Iterator<ImageReader> iter = ImageIO.getImageReaders(iis); if (!iter.hasNext()) { iis.close(); throw new IOException("No image detected in response"); } final ImageReader imageReader = iter.next(); imageReader.setInput(iis); imageData_ = new ImageData(imageReader); // dispose all others while (iter.hasNext()) { iter.next().dispose(); } } }
public int getHeight() { final HtmlImage img = (HtmlImage) getDomNodeOrDie(); final String height = img.getHeightAttribute(); final String src = img.getSrcAttribute(); if (DomElement.ATTRIBUTE_NOT_DEFINED == src) { final BrowserVersion browserVersion = getBrowserVersion(); return img.getHeight();