Search in sources :

Example 41 with Document

use of org.jsoup.nodes.Document in project jsoup by jhy.

the class SelectorTest method mixCombinator.

@Test
public void mixCombinator() {
    String h = "<div class=foo><ol><li>One<li>Two<li>Three</ol></div>";
    Document doc = Jsoup.parse(h);
    Elements sibs = doc.select("body > div.foo li + li");
    assertEquals(2, sibs.size());
    assertEquals("Two", sibs.get(0).text());
    assertEquals("Three", sibs.get(1).text());
}
Also used : Document(org.jsoup.nodes.Document) Test(org.junit.Test)

Example 42 with Document

use of org.jsoup.nodes.Document in project jsoup by jhy.

the class SelectorTest method deeperDescendant.

@Test
public void deeperDescendant() {
    String h = "<div class=head><p><span class=first>Hello</div><div class=head><p class=first><span>Another</span><p>Again</div>";
    Document doc = Jsoup.parse(h);
    Element root = doc.getElementsByClass("head").first();
    Elements els = root.select("div p .first");
    assertEquals(1, els.size());
    assertEquals("Hello", els.first().text());
    assertEquals("span", els.first().tagName());
    Elements aboveRoot = root.select("body p .first");
    assertEquals(0, aboveRoot.size());
}
Also used : Element(org.jsoup.nodes.Element) Document(org.jsoup.nodes.Document) Test(org.junit.Test)

Example 43 with Document

use of org.jsoup.nodes.Document in project jsoup by jhy.

the class SelectorTest method notParas.

@Test
public void notParas() {
    Document doc = Jsoup.parse("<p id=1>One</p> <p>Two</p> <p><span>Three</span></p>");
    Elements el1 = doc.select("p:not([id=1])");
    assertEquals(2, el1.size());
    assertEquals("Two", el1.first().text());
    assertEquals("Three", el1.last().text());
    Elements el2 = doc.select("p:not(:has(span))");
    assertEquals(2, el2.size());
    assertEquals("One", el2.first().text());
    assertEquals("Two", el2.last().text());
}
Also used : Document(org.jsoup.nodes.Document) Test(org.junit.Test)

Example 44 with Document

use of org.jsoup.nodes.Document in project jsoup by jhy.

the class SelectorTest method containsWithQuote.

@Test
public void containsWithQuote() {
    String html = "<p>One'One</p><p>One'Two</p>";
    Document doc = Jsoup.parse(html);
    Elements els = doc.select("p:contains(One\\'One)");
    assertEquals(1, els.size());
    assertEquals("One'One", els.text());
}
Also used : Document(org.jsoup.nodes.Document) Test(org.junit.Test)

Example 45 with Document

use of org.jsoup.nodes.Document in project jsoup by jhy.

the class SelectorTest method testPseudoGreaterThan.

@Test
public void testPseudoGreaterThan() {
    Document doc = Jsoup.parse("<div><p>One</p><p>Two</p><p>Three</p></div><div><p>Four</p>");
    Elements ps = doc.select("div p:gt(0)");
    assertEquals(2, ps.size());
    assertEquals("Two", ps.get(0).text());
    assertEquals("Three", ps.get(1).text());
}
Also used : Document(org.jsoup.nodes.Document) Test(org.junit.Test)

Aggregations

Document (org.jsoup.nodes.Document)391 Test (org.junit.Test)194 Element (org.jsoup.nodes.Element)153 IOException (java.io.IOException)100 File (java.io.File)81 Elements (org.jsoup.select.Elements)70 ElementHandlerImpl (org.asqatasun.ruleimplementation.ElementHandlerImpl)51 Connection (org.jsoup.Connection)37 ArrayList (java.util.ArrayList)36 URL (java.net.URL)24 HashMap (java.util.HashMap)16 InputStream (java.io.InputStream)13 List (java.util.List)9 MalformedURLException (java.net.MalformedURLException)8 Matcher (java.util.regex.Matcher)7 Logger (org.slf4j.Logger)7 Pattern (java.util.regex.Pattern)6 HttpGet (org.apache.http.client.methods.HttpGet)6 Jsoup (org.jsoup.Jsoup)6 LoggerFactory (org.slf4j.LoggerFactory)6