2013-06-03 225 views
0

這是一個下載google.com並解析它的程序。JSOUP解析XYZ.tor2web.org

Document doc = Jsoup.connect("http://www.google.com").timeout(3000000).userAgent("Mozilla").get(); 
     Elements links = doc.select("a[href]"); 
     for(Element l: links){ 
      String link = l.attr("abs:href"); 
      System.out.println(link); 
     } 

這工作所有丹迪和打印出的鏈接。但是,如果我改變了解析URL這樣:

Document doc = Jsoup.connect("http://idnxcnkne4qt76tg.tor2web.org").timeout(3000000).userAgent("Mozilla").get();  

然後輸出這個錯誤:

Exception in thread "main" javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target 
at sun.security.ssl.Alerts.getSSLException(Unknown Source) 
at sun.security.ssl.SSLSocketImpl.fatal(Unknown Source) 
at sun.security.ssl.Handshaker.fatalSE(Unknown Source) 
at sun.security.ssl.Handshaker.fatalSE(Unknown Source) 
at sun.security.ssl.ClientHandshaker.serverCertificate(Unknown Source) 
at sun.security.ssl.ClientHandshaker.processMessage(Unknown Source) 
at sun.security.ssl.Handshaker.processLoop(Unknown Source) 
at sun.security.ssl.Handshaker.process_record(Unknown Source) 
at sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source) 
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source) 
at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source) 
at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source) 
at sun.net.www.protocol.https.HttpsClient.afterConnect(Unknown Source) 
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(Unknown Source) 
at sun.net.www.protocol.https.HttpsURLConnectionImpl.connect(Unknown Source) 
at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:425) 
at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:446) 
at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:410) 
at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:164) 
at org.jsoup.helper.HttpConnection.get(HttpConnection.java:153) 
at quiz.MultipleChoice.main(MultipleChoice.java:10) 
Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target 
at sun.security.validator.PKIXValidator.doBuild(Unknown Source) 
at sun.security.validator.PKIXValidator.engineValidate(Unknown Source) 
at sun.security.validator.Validator.validate(Unknown Source) 
at sun.security.ssl.X509TrustManagerImpl.validate(Unknown Source) 
at sun.security.ssl.X509TrustManagerImpl.checkTrusted(Unknown Source) 
at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(Unknown Source) 
... 17 more 
Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target 
at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(Unknown Source) 
at java.security.cert.CertPathBuilder.build(Unknown Source) 
... 23 more 

幫助嗎?

回答

0

這是因爲你用HTTP需要而HTTP小號,或者:您可以使用一個簡單的連接,同時加密的預期。

如果你瀏覽到http://idnxcnkne4qt76tg.tor2web.org,你會被重定向到https://idnxcnkne4qt76tg.tor2web.org/

再次使用第二個URL(與https://)和測試。