简体   繁体   English

Jsoup。 如何在没有多个连接的情况下进行多个Web查询?

[英]Jsoup. How to multiple web query without multiple connection?

I'm making Android App with Jsoup. 我正在用Jsoup制作Android App。 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) (大约2.4秒。我想每个连接为0.8秒)

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). 但是,我认为它们是相同的URL ..因此,可能仅通过1个连接即可获得3个区域数据(比0.8秒略多)。

Is is possible? 有可能吗?

It is not possible to add connection pooling to Jsoup unless you create a new implementation of org.jsoup.Connection. 除非您创建org.jsoup.Connection的新实现,否则无法将连接池添加到Jsoup。

Underneath the hood, Jsoup uses org.jsoup.helpers.HTTPConnection as the implementation of this interface. 在底层,Jsoup使用org.jsoup.helpers.HTTPConnection作为此接口的实现。

In particular, you would need to modify how the Response class handles the java.net.HttpURLConnection object. 特别是,您将需要修改Response类处理java.net.HttpURLConnection对象的方式。 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 https://github.com/jhy/jsoup/tree/master/src/main/java/org/jsoup/helper

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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