HtmlElement e = page.getFirstByXPath("//button[span[text()='Log In']]"); System.out.println(e.asXml());
/** * 使用HtmlUnit获取页面内容,HtmlUnit能执行JS,动态渲染网页,但不是所有JS都能渲染,需要测试 * @param url html页面路径 * @return */ @Override public String fetch(String url) { try{ LOGGER.debug("url:"+url); HtmlPage htmlPage = WEB_CLIENT.getPage(url); String html = htmlPage.getBody().asXml(); LOGGER.debug("html:"+html); return html; }catch (Exception e) { LOGGER.error("获取URL:"+url+"页面出错", e); } return ""; }
public String getHtmlContents() { return currentPage().getElement(0).asXml(); }
public class HtmlUnitTest { public static void main(String[] args) throws FailingHttpStatusCodeException, MalformedURLException, IOException { final WebClient webClient = new WebClient(); final HtmlPage page = webClient.getPage("http://www.google.com"); System.out.println(page.getTitleText()); for (HtmlElement node : page.getHtmlElementDescendants()) { if (node.getTagName().toUpperCase().equals("IMG")) { System.out.println("NAME: " + node.getTagName()); System.out.println("WIDTH:" + node.getAttribute("width")); System.out.println("HEIGHT:" + node.getAttribute("height")); System.out.println("TEXT: " + node.asText()); System.out.println("XMl: " + node.asXml()); } } } }
String xml = h.asXml(); colNames.add(h.asText());
if ((classValue == null) || (!classValue.equals("rich-tree-node-handle"))) throw new IllegalArgumentException("treeHandle element is not a RichFaces tree node handle: " + treeHandle.asXml());
String xml = Util.cleanString(cell.asXml()); DomNodeList<HtmlElement> anchors;
if (children.hasNext()) { final HtmlElement root = children.next(); document.jsxFunction_loadXML(root.asXml().trim());
if (children.hasNext()) { final HtmlElement root = children.next(); document.jsxFunction_loadXML(root.asXml().trim());
if (children.hasNext()) { final HtmlElement root = children.next(); document.jsxFunction_loadXML(root.asXml().trim());