HtmlAnchor a = (HtmlAnchor)ele; url = a.getHrefAttribute();
Page kmlPage = null; for (HtmlAnchor a : downloadPage.getAnchors()) { if (a.getHrefAttribute().contains("trip/27887/download/?fileformat=kml")) { String url = a.getHrefAttribute(); if (!url.startsWith("http")) { url = "http://www.hostname.com" + url; } kmlPage = client.getPage(url); // you can also do it it simplier if this below works // kmlPage = a.click(); } } String contentType = kmlPage.getWebResponse().getContentType(); if (contentType.contains("kml")) { InputStream kmlStream = factPage.getWebResponse().getContentAsStream(); }
private HtmlAnchor getAnchor(String string) { for (HtmlAnchor n : page.getAnchors()) { if (n.getHrefAttribute().contains(string)) return n; } return null; } /*
HtmlPage htmlPage = new WebClient().getPage("http://imdb.com/blah"); HtmlAnchor anchor = htmlPage.getFirstByXPath("//td[@class='primary_photo']//a") System.out.println(anchor.getHrefAttribute());
/** * Sets the focus to this element. */ @Override public void focus() { final HtmlAnchor anchor = (HtmlAnchor) getDomNodeOrDie(); final String hrefAttr = anchor.getHrefAttribute(); if (hrefAttr != DomElement.ATTRIBUTE_NOT_DEFINED) { anchor.focus(); } }
/** * Sets the focus to this element. */ @Override public void focus() { final HtmlAnchor anchor = (HtmlAnchor) getDomNodeOrDie(); final String hrefAttr = anchor.getHrefAttribute(); if (hrefAttr != DomElement.ATTRIBUTE_NOT_DEFINED) { anchor.focus(); } }
private void parseDownloadURL(HtmlAnchor a, Book b) { String url = a.getHrefAttribute(); HashMap<String, String> args = Util.urlGetArgs(url); for (String k : args.keySet()) { BookElement elem = BookElement.findByName(k); if (elem != null) { b.set(elem, args.get(k)); } } }
/** * Returns the value of this link's <tt>href</tt> property. * @return the value of this link's <tt>href</tt> property */ public String jsxGet_href() { final HtmlAnchor anchor = (HtmlAnchor) getDomNodeOrDie(); final String hrefAttr = anchor.getHrefAttribute(); if (hrefAttr == HtmlAnchor.ATTRIBUTE_NOT_DEFINED) { return ""; } try { return getUrl().toString(); } catch (final MalformedURLException e) { return hrefAttr; } }
/** * Returns the value of this link's <tt>href</tt> property. * @return the value of this link's <tt>href</tt> property */ public String jsxGet_href() { final HtmlAnchor anchor = (HtmlAnchor) getDomNodeOrDie(); final String hrefAttr = anchor.getHrefAttribute(); if (hrefAttr == HtmlAnchor.ATTRIBUTE_NOT_DEFINED) { return ""; } try { return getUrl().toString(); } catch (final MalformedURLException e) { return hrefAttr; } }
/** * Returns the value of this link's <tt>href</tt> property. * @return the value of this link's <tt>href</tt> property */ public String jsxGet_href() { final HtmlAnchor anchor = (HtmlAnchor) getDomNodeOrDie(); final String hrefAttr = anchor.getHrefAttribute(); if (hrefAttr == HtmlAnchor.ATTRIBUTE_NOT_DEFINED) { return ""; } try { return getUrl().toString(); } catch (final MalformedURLException e) { return hrefAttr; } }
/** * Returns this link's current URL. * @return this link's current URL * @throws MalformedURLException if an error occurs */ private URL getUrl() throws MalformedURLException { final HtmlAnchor anchor = (HtmlAnchor) getDomNodeOrDie(); return ((HtmlPage) anchor.getPage()).getFullyQualifiedUrl(anchor.getHrefAttribute()); }
/** * Returns this link's current URL. * @return this link's current URL * @throws MalformedURLException if an error occurs */ private URL getUrl() throws MalformedURLException { final HtmlAnchor anchor = (HtmlAnchor) getDomNodeOrDie(); return ((HtmlPage) anchor.getPage()).getFullyQualifiedUrl(anchor.getHrefAttribute()); }
/** * Returns the value of this link's {@code href} property. * @return the value of this link's {@code href} property */ @JsxGetter public String getHref() { final HtmlAnchor anchor = (HtmlAnchor) getDomNodeOrDie(); final String hrefAttr = anchor.getHrefAttribute(); if (hrefAttr == DomElement.ATTRIBUTE_NOT_DEFINED) { return ""; } try { return getUrl().toString(); } catch (final MalformedURLException e) { return hrefAttr; } }
/** * Returns this link's current URL. * @return this link's current URL * @throws MalformedURLException if an error occurs */ private URL getUrl() throws MalformedURLException { final HtmlAnchor anchor = (HtmlAnchor) getDomNodeOrDie(); return ((HtmlPage) anchor.getPage()).getFullyQualifiedUrl(anchor.getHrefAttribute()); }
/** * Returns this link's current URL. * @return this link's current URL * @throws MalformedURLException if an error occurs */ private URL getUrl() throws MalformedURLException { final HtmlAnchor anchor = (HtmlAnchor) getDomNodeOrDie(); return ((HtmlPage) anchor.getPage()).getFullyQualifiedUrl(anchor.getHrefAttribute()); }
/** * Returns this link's current URL. * @return this link's current URL * @throws MalformedURLException if an error occurs */ private URL getUrl() throws MalformedURLException { final HtmlAnchor anchor = (HtmlAnchor) getDomNodeOrDie(); return ((HtmlPage) anchor.getPage()).getFullyQualifiedUrl(anchor.getHrefAttribute()); }
public void assertNoLink(String url) { List<HtmlAnchor> anchors = htmlPage.getAnchors(); boolean found = false; String fullUrl = getHrefFromTestUrl(url); for (HtmlAnchor anchor : anchors) { if (fullUrl.equals(anchor.getHrefAttribute())) { found = true; break; } } assertFalse("Link to " + fullUrl + " found, but should not be present", found); } }
/** * Open this link in a new window, much as web browsers do when you shift-click a link or use the context * menu to open in a new window. * * It should be noted that even web browsers will sometimes not give the expected result when using this * method of following links. Links that have no real href and rely on JavaScript to do their work will * fail. * * @return the page opened by this link, nested in a new {@link com.gargoylesoftware.htmlunit.TopLevelWindow} * @throws MalformedURLException if the href could not be converted to a valid URL */ public final Page openLinkInNewWindow() throws MalformedURLException { final URL target = ((HtmlPage) getPage()).getFullyQualifiedUrl(getHrefAttribute()); final String windowName = "HtmlAnchor.openLinkInNewWindow() target"; final WebWindow newWindow = getPage().getWebClient().openWindow(target, windowName); return newWindow.getEnclosedPage(); }
/** * Open this link in a new window, much as web browsers do when you shift-click a link or use the context * menu to open in a new window. * * It should be noted that even web browsers will sometimes not give the expected result when using this * method of following links. Links that have no real href and rely on JavaScript to do their work will * fail. * * @return the page opened by this link, nested in a new {@link com.gargoylesoftware.htmlunit.TopLevelWindow} * @throws MalformedURLException if the href could not be converted to a valid URL */ public final Page openLinkInNewWindow() throws MalformedURLException { final URL target = ((HtmlPage) getPage()).getFullyQualifiedUrl(getHrefAttribute()); final String windowName = "HtmlAnchor.openLinkInNewWindow() target"; final WebWindow newWindow = getPage().getWebClient().openWindow(target, windowName); return newWindow.getEnclosedPage(); } }
/** * Open this link in a new window, much as web browsers do when you shift-click a link or use the context * menu to open in a new window. * * It should be noted that even web browsers will sometimes not give the expected result when using this * method of following links. Links that have no real href and rely on JavaScript to do their work will * fail. * * @return the page opened by this link, nested in a new {@link com.gargoylesoftware.htmlunit.TopLevelWindow} * @throws MalformedURLException if the href could not be converted to a valid URL */ public final Page openLinkInNewWindow() throws MalformedURLException { final URL target = ((HtmlPage) getPage()).getFullyQualifiedUrl(getHrefAttribute()); final String windowName = "HtmlAnchor.openLinkInNewWindow() target"; final WebWindow newWindow = getPage().getWebClient().openWindow(target, windowName); return newWindow.getEnclosedPage(); }