我正在使用Eclipse的一个简单的Jsoup程序,但是当我尝试运行该程序并向我的程序添加更多步骤时,如java.net.SocketTimeoutException: connect timed out
。Eclipse中的Java Jsoup程序引发java.net.SocketTimeoutException:连接超时
此代码工作正常:
public static void main(String[] args) {
Document doc;
try {
doc = Jsoup.connect("http://google.com").get();
System.out.println("doc is = " + doc);
} catch (IOException e) {
e.printStackTrace();
}
}
,我也得到了一些XML数据作为输出。
现在,当我这个程序更改为:
public static void main(String[] args) {
Document doc;
try {
// need http protocol
doc = Jsoup.connect("http://google.com").get();
System.out.println("doc is = " + doc);
// get page title
String title = doc.title();
System.out.println("title : " + title);
// get all links
Elements links = doc.select("a[href]");
for (Element link : links) {
// get the value from href attribute
System.out.println("\nlink : " + link.attr("href"));
System.out.println("text : " + link.text());
}
} catch (IOException e) {
e.printStackTrace();
}
}
然后我得到的例外是:java.net.SocketTimeoutException: connect timed out
看来我需要设置超时选项,请让我知道我能做到这一点的蚀?
我刚才提到的下方,职位,但仍面临着同样的问题,我也没有任何代理之间访问互联网:
Sometimes java.net.SocketTimeoutException: Read timed out. Sometimes not
不错,值得注意的是,虽然在** MOST **案件不建议。 – God