我正在试着从一个网站上提取一些信息。这是它的代码。
Connection conn = Jsoup.connect(s_url); //s_url has been initialized to contain the url
conn.timeout(300000); //5 minutes
Document doc = conn.get();
//some code
连接似乎需要相当多的时间,大约8-10秒。我正在尝试显示类似这样的内容
Connecting...
在建立连接的同时,点数增加。有没有办法检查连接是不是已经用jsoup建立了?如果没有,有没有可能在Java中用其他方式来做呢?
发布于 2014-01-10 09:07:40
我建议你使用线程。生成一个将连接到服务器的线程,并在主线程中等待它完成,同时打印点:
Thread t = new Thread(
new Runnable() {
public void run() {
System.out.println("Connecting");
try{
loginForm = Jsoup.connect(s_url).execute();
}catch (Exception e){
}
}
}
);
t.start();
while(t.isAlive()){
Thread.sleep(1000); //1 second
System.out.print(".");
}
https://stackoverflow.com/questions/21016144
复制相似问题