Search in sources :

Example 6 with Elements

use of org.jsoup.select.Elements in project jsoup by jhy.

the class ParseTest method testSmhBizArticle.

@Test
public void testSmhBizArticle() throws IOException {
    File in = getFile("/htmltests/smh-biz-article-1.html");
    Document doc = Jsoup.parse(in, "UTF-8", "http://www.smh.com.au/business/the-boards-next-fear-the-female-quota-20100106-lteq.html");
    assertEquals("The board’s next fear: the female quota", // note that the apos in the source is a literal ’ (8217), not escaped or '
    doc.title());
    assertEquals("en", doc.select("html").attr("xml:lang"));
    Elements articleBody = doc.select(".articleBody > *");
    assertEquals(17, articleBody.size());
// todo: more tests!
}
Also used : Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements) Test(org.junit.Test)

Example 7 with Elements

use of org.jsoup.select.Elements in project jsoup by jhy.

the class AttributeParseTest method strictAttributeUnescapes.

@Test
public void strictAttributeUnescapes() {
    String html = "<a id=1 href='?foo=bar&mid&lt=true'>One</a> <a id=2 href='?foo=bar&lt;qux&lg=1'>Two</a>";
    Elements els = Jsoup.parse(html).select("a");
    assertEquals("?foo=bar&mid&lt=true", els.first().attr("href"));
    assertEquals("?foo=bar<qux&lg=1", els.last().attr("href"));
}
Also used : Elements(org.jsoup.select.Elements) Test(org.junit.Test)

Example 8 with Elements

use of org.jsoup.select.Elements in project jsoup by jhy.

the class ElementTest method testPrependNewHtml.

@Test
public void testPrependNewHtml() {
    Document doc = Jsoup.parse("<div id=1><p>Hello</p></div>");
    Element div = doc.getElementById("1");
    div.prepend("<p>there</p><p>now</p>");
    assertEquals("<p>there</p><p>now</p><p>Hello</p>", TextUtil.stripNewlines(div.html()));
    // check sibling index (reindexChildren):
    Elements ps = doc.select("p");
    for (int i = 0; i < ps.size(); i++) {
        assertEquals(i, ps.get(i).siblingIndex);
    }
}
Also used : Elements(org.jsoup.select.Elements) Test(org.junit.Test)

Example 9 with Elements

use of org.jsoup.select.Elements in project jsoup by jhy.

the class ElementTest method insertChildrenAtPosition.

@Test
public void insertChildrenAtPosition() {
    Document doc = Jsoup.parse("<div id=1>Text1 <p>One</p> Text2 <p>Two</p></div><div id=2>Text3 <p>Three</p></div>");
    Element div1 = doc.select("div").get(0);
    Elements p1s = div1.select("p");
    Element div2 = doc.select("div").get(1);
    assertEquals(2, div2.childNodeSize());
    div2.insertChildren(-1, p1s);
    // moved two out
    assertEquals(2, div1.childNodeSize());
    assertEquals(4, div2.childNodeSize());
    // should be last
    assertEquals(3, p1s.get(1).siblingIndex());
    List<Node> els = new ArrayList<Node>();
    Element el1 = new Element(Tag.valueOf("span"), "").text("Span1");
    Element el2 = new Element(Tag.valueOf("span"), "").text("Span2");
    TextNode tn1 = new TextNode("Text4", "");
    els.add(el1);
    els.add(el2);
    els.add(tn1);
    assertNull(el1.parent());
    div2.insertChildren(-2, els);
    assertEquals(div2, el1.parent());
    assertEquals(7, div2.childNodeSize());
    assertEquals(3, el1.siblingIndex());
    assertEquals(4, el2.siblingIndex());
    assertEquals(5, tn1.siblingIndex());
}
Also used : Elements(org.jsoup.select.Elements) Test(org.junit.Test)

Example 10 with Elements

use of org.jsoup.select.Elements in project jsoup by jhy.

the class ElementTest method testHasText.

@Test
public void testHasText() {
    Document doc = Jsoup.parse("<div><p>Hello</p><p></p></div>");
    Element div = doc.select("div").first();
    Elements ps = doc.select("p");
    assertTrue(div.hasText());
    assertTrue(ps.first().hasText());
    assertFalse(ps.last().hasText());
}
Also used : Elements(org.jsoup.select.Elements) Test(org.junit.Test)

Aggregations

Elements (org.jsoup.select.Elements)168 Element (org.jsoup.nodes.Element)96 Document (org.jsoup.nodes.Document)70 ArrayList (java.util.ArrayList)38 Test (org.junit.Test)33 IOException (java.io.IOException)24 URL (java.net.URL)13 ParseTest (org.jsoup.integration.ParseTest)11 File (java.io.File)9 List (java.util.List)8 HashMap (java.util.HashMap)7 SSPHandler (org.asqatasun.processor.SSPHandler)7 TestSolutionHandler (org.asqatasun.ruleimplementation.TestSolutionHandler)7 ProcessRemarkService (org.asqatasun.service.ProcessRemarkService)7 MalformedURLException (java.net.MalformedURLException)6 Logger (org.slf4j.Logger)5 LoggerFactory (org.slf4j.LoggerFactory)5 TextView (android.widget.TextView)4 RequestUtil (com.kyj.fx.voeditor.visual.util.RequestUtil)4 ResponseHandler (com.kyj.fx.voeditor.visual.util.ResponseHandler)4