Search in sources :

Example 31 with Document

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

the class ElementsTest method is.

@Test
public void is() {
    String h = "<p>Hello<p title=foo>there<p>world";
    Document doc = Jsoup.parse(h);
    Elements ps = doc.select("p");
    assertTrue(ps.is("[title=foo]"));
    assertFalse(ps.is("[title=bar]"));
}
Also used : Document(org.jsoup.nodes.Document) Test(org.junit.Test)

Example 32 with Document

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

the class ElementsTest method wrapDiv.

@Test
public void wrapDiv() {
    String h = "<p><b>This</b> is <b>jsoup</b>.</p> <p>How do you like it?</p>";
    Document doc = Jsoup.parse(h);
    doc.select("p").wrap("<div></div>");
    assertEquals("<div><p><b>This</b> is <b>jsoup</b>.</p></div> <div><p>How do you like it?</p></div>", TextUtil.stripNewlines(doc.body().html()));
}
Also used : Document(org.jsoup.nodes.Document) Test(org.junit.Test)

Example 33 with Document

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

the class ElementsTest method unwrap.

@Test
public void unwrap() {
    String h = "<div><font>One</font> <font><a href=\"/\">Two</a></font></div";
    Document doc = Jsoup.parse(h);
    doc.select("font").unwrap();
    assertEquals("<div>One <a href=\"/\">Two</a></div>", TextUtil.stripNewlines(doc.body().html()));
}
Also used : Document(org.jsoup.nodes.Document) Test(org.junit.Test)

Example 34 with Document

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

the class XmlTreeBuilderTest method testDoesHandleEOFInTag.

@Test
public void testDoesHandleEOFInTag() {
    String html = "<img src=asdf onerror=\"alert(1)\" x=";
    Document xmlDoc = Jsoup.parse(html, "", Parser.xmlParser());
    assertEquals("<img src=\"asdf\" onerror=\"alert(1)\" x=\"\" />", xmlDoc.html());
}
Also used : Document(org.jsoup.nodes.Document) Test(org.junit.Test)

Example 35 with Document

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

the class XmlTreeBuilderTest method testCreatesValidProlog.

@Test
public void testCreatesValidProlog() {
    Document document = Document.createShell("");
    document.outputSettings().syntax(Syntax.xml);
    document.charset(Charset.forName("utf-8"));
    assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<html>\n" + " <head></head>\n" + " <body></body>\n" + "</html>", document.outerHtml());
}
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