Search in sources :

Example 16 with Document

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

the class UrlConnectTest method doesGet.

@Test
public void doesGet() throws IOException {
    Connection con = Jsoup.connect(echoURL + "?what=the").userAgent("Mozilla").referrer("http://example.com").data("what", "about & me?");
    Document doc = con.get();
    assertEquals("what=the&what=about+%26+me%3F", ihVal("QUERY_STRING", doc));
    assertEquals("the, about & me?", ihVal("what", doc));
    assertEquals("Mozilla", ihVal("HTTP_USER_AGENT", doc));
    assertEquals("http://example.com", ihVal("HTTP_REFERER", doc));
}
Also used : Connection(org.jsoup.Connection) Document(org.jsoup.nodes.Document) Test(org.junit.Test)

Example 17 with Document

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

the class UrlConnectTest method followsRelativeRedirect.

@Test
public void followsRelativeRedirect() throws IOException {
    // to /tidy/
    Connection con = Jsoup.connect("http://direct.infohound.net/tools/302-rel.pl");
    Document doc = con.post();
    assertTrue(doc.title().contains("HTML Tidy Online"));
}
Also used : Connection(org.jsoup.Connection) Document(org.jsoup.nodes.Document) Test(org.junit.Test)

Example 18 with Document

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

the class UrlConnectTest method redirectsResponseCookieToNextResponse.

@Test
public void redirectsResponseCookieToNextResponse() throws IOException {
    Connection con = Jsoup.connect("http://direct.infohound.net/tools/302-cookie.pl");
    Connection.Response res = con.execute();
    // confirms that cookies set on 1st hit are presented in final result
    assertEquals("asdfg123", res.cookie("token"));
    Document doc = res.parse();
    // confirms that redirected hit saw cookie
    assertEquals("token=asdfg123; uid=jhy", ihVal("HTTP_COOKIE", doc));
}
Also used : Connection(org.jsoup.Connection) Document(org.jsoup.nodes.Document) Test(org.junit.Test)

Example 19 with Document

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

the class UrlConnectTest method fetchURl.

@Test
public void fetchURl() throws IOException {
    // no trailing / to force redir
    String url = "https://jsoup.org";
    Document doc = Jsoup.parse(new URL(url), 10 * 1000);
    assertTrue(doc.title().contains("jsoup"));
}
Also used : Document(org.jsoup.nodes.Document) URL(java.net.URL) Test(org.junit.Test)

Example 20 with Document

use of org.jsoup.nodes.Document 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)

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