Search in sources :

Example 46 with Document

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

the class SelectorTest method testCombinedWithContains.

@Test
public void testCombinedWithContains() {
    Document doc = Jsoup.parse("<p id=1>One</p><p>Two +</p><p>Three +</p>");
    Elements els = doc.select("p#1 + :contains(+)");
    assertEquals(1, els.size());
    assertEquals("Two +", els.text());
    assertEquals("p", els.first().tagName());
}
Also used : Document(org.jsoup.nodes.Document) Test(org.junit.Test)

Example 47 with Document

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

the class SelectorTest method adjacentSiblingsWithId.

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

Example 48 with Document

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

the class SelectorTest method testPseudoContains.

@Test
public void testPseudoContains() {
    Document doc = Jsoup.parse("<div><p>The Rain.</p> <p class=light>The <i>rain</i>.</p> <p>Rain, the.</p></div>");
    Elements ps1 = doc.select("p:contains(Rain)");
    assertEquals(3, ps1.size());
    Elements ps2 = doc.select("p:contains(the rain)");
    assertEquals(2, ps2.size());
    assertEquals("The Rain.", ps2.first().html());
    assertEquals("The <i>rain</i>.", ps2.last().html());
    Elements ps3 = doc.select("p:contains(the Rain):has(i)");
    assertEquals(1, ps3.size());
    assertEquals("light", ps3.first().className());
    Elements ps4 = doc.select(".light:contains(rain)");
    assertEquals(1, ps4.size());
    assertEquals("light", ps3.first().className());
    Elements ps5 = doc.select(":contains(rain)");
    // html, body, div,...
    assertEquals(8, ps5.size());
}
Also used : Document(org.jsoup.nodes.Document) Test(org.junit.Test)

Example 49 with Document

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

the class SelectorTest method multiChildDescent.

@Test
public void multiChildDescent() {
    String h = "<div id=foo><h1 class=bar><a href=http://example.com/>One</a></h1></div>";
    Document doc = Jsoup.parse(h);
    Elements els = doc.select("div#foo > h1.bar > a[href*=example]");
    assertEquals(1, els.size());
    assertEquals("a", els.first().tagName());
}
Also used : Document(org.jsoup.nodes.Document) Test(org.junit.Test)

Example 50 with Document

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

the class SelectorTest method testPseudoEquals.

@Test
public void testPseudoEquals() {
    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:eq(0)");
    assertEquals(2, ps.size());
    assertEquals("One", ps.get(0).text());
    assertEquals("Four", ps.get(1).text());
    Elements ps2 = doc.select("div:eq(0) p:eq(0)");
    assertEquals(1, ps2.size());
    assertEquals("One", ps2.get(0).text());
    assertEquals("p", ps2.get(0).tagName());
}
Also used : Document(org.jsoup.nodes.Document) Test(org.junit.Test)

Aggregations

Document (org.jsoup.nodes.Document)405 Test (org.junit.Test)194 Element (org.jsoup.nodes.Element)164 IOException (java.io.IOException)102 File (java.io.File)81 Elements (org.jsoup.select.Elements)78 ElementHandlerImpl (org.asqatasun.ruleimplementation.ElementHandlerImpl)51 ArrayList (java.util.ArrayList)41 Connection (org.jsoup.Connection)38 URL (java.net.URL)25 HashMap (java.util.HashMap)17 InputStream (java.io.InputStream)14 List (java.util.List)10 MalformedURLException (java.net.MalformedURLException)8 Logger (org.slf4j.Logger)8 Matcher (java.util.regex.Matcher)7 Jsoup (org.jsoup.Jsoup)7 LoggerFactory (org.slf4j.LoggerFactory)7 Pattern (java.util.regex.Pattern)6 HttpGet (org.apache.http.client.methods.HttpGet)6