I am trying to parse some url's with Jsoup but I get this error:
java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
here is my code:
public Elements getLinks(String link){
Document doc = null;
Elements links = null;
try {
doc = Jsoup.connect(link)
.userAgent("Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:25.0) Gecko/20100101 Firefox/25.0")
.referrer("http://www.google.com")
.timeout(5000) //it's in milliseconds, so this means 5 seconds.
.get();
links = doc.select("a[href]");
}
catch (ConnectException e){
e.printStackTrace();
}
catch (UnsupportedMimeTypeException e){
e.printStackTrace();
}
catch (SocketTimeoutException e){
e.printStackTrace();
}
catch (SSLException e) {
e.printStackTrace();
}
catch (IOException e) {
if(e.getCause() instanceof SocketTimeoutException) {
try {
throw new SocketTimeoutException();
} catch (SocketTimeoutException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
e.printStackTrace();
}
return links;
}
I have a catch section for the ConnectException but my program stops.. Any ideas how to fix this problem?
http/https
)? – Kayamanmulticatch
. – lonesome