简体   繁体   中英

Jsoup. How to multiple web query without multiple connection?

I'm making Android App with Jsoup. My code is as below.

String URL = “http://www.example.com/queryDFSRSS.jsp?zone=“
String zone_1 = “001”;
String zone_2 = “002”;
String zone_3 = “003”;

Document doc = Jsoup.connect(URL+zone_1).get();
. . . . 
doc = Jsoup.connect(URL+zone_2).get();
. . . . .
doc = Jsoup.connect(URL+zone_3).get();
.. . . . 

It takes long time. (about 2.4sec.. I guess, 0.8sec for each connection)

But, I think that they are same URL.. so it may be possible to get 3 zone data only 1 connection(slightly more times than 0.8 sec).

Is is possible?

It is not possible to add connection pooling to Jsoup unless you create a new implementation of org.jsoup.Connection.

Underneath the hood, Jsoup uses org.jsoup.helpers.HTTPConnection as the implementation of this interface.

In particular, you would need to modify how the Response class handles the java.net.HttpURLConnection object. Here is the current implementation:

HTTPConnection.Response.execute(Connection.Request req, Response previousResponse) {

    HttpURLConnection conn = createConnection(req);
    ...
    conn.connect();
    ...
    conn.disconnect();

}

https://github.com/jhy/jsoup/tree/master/src/main/java/org/jsoup/helper

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM