Search in sources :

Example 16 with Connection

use of org.jsoup.Connection in project jsoup by jhy.

the class HttpConnectionTest method userAgent.

@Test
public void userAgent() {
    Connection con = HttpConnection.connect("http://example.com/");
    assertEquals(HttpConnection.DEFAULT_UA, con.request().header("User-Agent"));
    con.userAgent("Mozilla");
    assertEquals("Mozilla", con.request().header("User-Agent"));
}
Also used : Connection(org.jsoup.Connection) Test(org.junit.Test) ParseTest(org.jsoup.integration.ParseTest)

Example 17 with Connection

use of org.jsoup.Connection in project jsoup by jhy.

the class UrlConnectTest method fetchHandlesXml.

@Test
public void fetchHandlesXml() throws IOException {
    // should auto-detect xml and use XML parser, unless explicitly requested the html parser
    String xmlUrl = "http://direct.infohound.net/tools/parse-xml.xml";
    Connection con = Jsoup.connect(xmlUrl);
    Document doc = con.get();
    Connection.Request req = con.request();
    assertTrue(req.parser().getTreeBuilder() instanceof XmlTreeBuilder);
    assertEquals("<xml> <link> one </link> <table> Two </table> </xml>", StringUtil.normaliseWhitespace(doc.outerHtml()));
}
Also used : Connection(org.jsoup.Connection) Document(org.jsoup.nodes.Document) XmlTreeBuilder(org.jsoup.parser.XmlTreeBuilder) Test(org.junit.Test)

Example 18 with Connection

use of org.jsoup.Connection in project jsoup by jhy.

the class UrlConnectTest method fetchURIWithWihtespace.

@Test
public void fetchURIWithWihtespace() throws IOException {
    Connection con = Jsoup.connect("http://try.jsoup.org/#with whitespaces");
    Document doc = con.get();
    assertTrue(doc.title().contains("jsoup"));
}
Also used : Connection(org.jsoup.Connection) Document(org.jsoup.nodes.Document) Test(org.junit.Test)

Example 19 with Connection

use of org.jsoup.Connection in project jsoup by jhy.

the class UrlConnectTest method handles200WithNoContent.

@Test
public void handles200WithNoContent() throws IOException {
    Connection con = Jsoup.connect("http://direct.infohound.net/tools/200-no-content.pl").userAgent(browserUa);
    Connection.Response res = con.execute();
    Document doc = res.parse();
    assertEquals(200, res.statusCode());
    con = Jsoup.connect("http://direct.infohound.net/tools/200-no-content.pl").parser(Parser.xmlParser()).userAgent(browserUa);
    res = con.execute();
    doc = res.parse();
    assertEquals(200, res.statusCode());
}
Also used : Connection(org.jsoup.Connection) Document(org.jsoup.nodes.Document) Test(org.junit.Test)

Example 20 with Connection

use of org.jsoup.Connection in project jsoup by jhy.

the class UrlConnectTest method gracefullyHandleBrokenLocationRedirect.

@Test
public void gracefullyHandleBrokenLocationRedirect() throws IOException {
    // has Location: http:/temp/AAG_New/en/index.php
    Connection con = Jsoup.connect("http://aag-ye.com");
    // would throw exception on error
    con.get();
    assertTrue(true);
}
Also used : Connection(org.jsoup.Connection) Test(org.junit.Test)

Aggregations

Connection (org.jsoup.Connection)47 Test (org.junit.Test)42 Document (org.jsoup.nodes.Document)26 ParseTest (org.jsoup.integration.ParseTest)13 IOException (java.io.IOException)3 URL (java.net.URL)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Element (org.jsoup.nodes.Element)2 Elements (org.jsoup.select.Elements)2 JsonArray (com.google.gson.JsonArray)1 JsonObject (com.google.gson.JsonObject)1 JsonParser (com.google.gson.JsonParser)1 JsonSyntaxException (com.google.gson.JsonSyntaxException)1 News (com.itculturalfestival.smartcampus.entity.News)1 DisposableHolder (com.vegen.smartcampus.baseframework.network.DisposableHolder)1 ObservableOnSubscribe (io.reactivex.ObservableOnSubscribe)1 Disposable (io.reactivex.disposables.Disposable)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1