/** * Creates node selector. */ protected NodeSelector createNodeSelector(final Node node) { return new NodeSelector(node); }
@Override public boolean match(final Node node, final List<List<CssSelector>> selectors) { List<Node> matchedNodes = new NodeSelector(node).select(selectors); return !matchedNodes.isEmpty(); } }
private NodeSelector createNodeFilter() throws IOException { File file = new File(testDataRoot, "one.html"); String html = FileUtil.readString(file); return new NodeSelector(new LagartoDOMBuilder().parse(html)); } }
@Test void test250() { String html = "<html>\n" + " <body>\n" + " <a href=\"/go?to=foobar&index=null\" title=\"Choice 1\">link</a>\n" + " </body>\n" + "</html>"; LagartoDOMBuilder domBuilder = new LagartoDOMBuilder(); NodeSelector nodeSelector = new NodeSelector(domBuilder.parse(html)); List<Node> selectedNodes = nodeSelector.select("a[title='Choice 1']"); System.out.println(); assertEquals("/go?to=foobar&index=null", selectedNodes.get(0).getAttribute("href")); }
@Test void testGroupOfSelectors() throws IOException { File file = new File(testDataRoot, "one.html"); String htmlContent = FileUtil.readString(file); Document document = new LagartoDOMBuilder().parse(htmlContent); List<Node> nodes = new NodeSelector(document).select("em, b, b"); assertEquals(9, nodes.size()); assertTrue(document.check()); }
@Test void testClassWithTabs() throws IOException { File file = new File(testDataRoot, "class-tabs.html"); String htmlContent = FileUtil.readString(file); Document document = new LagartoDOMBuilder().parse(htmlContent); List<Node> nodes = new NodeSelector(document).select(".hey"); assertEquals(1, nodes.size()); Node n = nodes.get(0); assertEquals("div", n.getNodeName()); assertEquals("jodd", n.getAttribute("id")); }
@Test void testTwoHtml() throws IOException { File file = new File(testDataRoot, "two.html"); String htmlContent = FileUtil.readString(file); Document document = new LagartoDOMBuilder().parse(htmlContent); Node html = new NodeSelector(document).select("html").get(0); assertNotNull(html); Node body = new NodeSelector(html).selectFirst("body"); Element h1 = body.getFirstChildElement(); assertEquals("h1", h1.getNodeName()); Node comment1 = body.getFirstChild().getNextSibling(); assertEquals(Node.NodeType.COMMENT, comment1.getNodeType()); Element p = (Element) new NodeSelector(body).selectFirst("p"); assertEquals(h1, p.getPreviousSiblingElement()); assertEquals(h1, comment1.getNextSiblingElement()); assertNull(comment1.getNextSiblingName()); // check if filter works just for sub elements List<Node> p_ems = new NodeSelector(p).select("em"); assertEquals(1, p_ems.size()); Element script = (Element) new NodeSelector(html).selectFirst("script"); assertEquals("text/javascript", script.getAttribute("type")); assertTrue(document.check()); }
NodeSelector nodeSelector = new NodeSelector(xml); List<Node> persons = nodeSelector.select("person");
document = new LagartoDOMBuilder().parse(html); NodeSelector nodeSelector = new NodeSelector(document); Element div = (Element) nodeSelector.selectFirst("div.ysites-col"); Element h2 = (Element) div.getFirstChild();
/** * Creates node selector. */ protected NodeSelector createNodeSelector(Node node) { return new NodeSelector(node); }
/** * Creates node selector. */ protected NodeSelector createNodeSelector(final Node node) { return new NodeSelector(node); }
/** * Creates node selector. */ protected NodeSelector createNodeSelector(Node node) { return new NodeSelector(node); }
@Override public boolean match(final Node node, final List<List<CssSelector>> selectors) { List<Node> matchedNodes = new NodeSelector(node).select(selectors); return !matchedNodes.isEmpty(); } }
LagartoDOMBuilder domBuilder = new LagartoDOMBuilder(); jodd.lagarto.dom.Document doc = domBuilder.parse(inputString); nodeSelector = new NodeSelector(doc); JMeterContextService.getContext().getSamplerContext().put(CACHE_KEY_PREFIX+cacheKey, nodeSelector); LagartoDOMBuilder domBuilder = new LagartoDOMBuilder(); jodd.lagarto.dom.Document doc = domBuilder.parse(inputString); nodeSelector = new NodeSelector(doc);