0
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.net.*;
import java.io.*;

public class ScaprefromWikipedia {

    public static void main(String[] args) throws Exception {

            Document doc = Jsoup.connect("https://en.wikipedia.org/wiki/Java_(programming_language)").get();
        
            System.out.println(doc);
    
    }       
}

The error I get :-

Exception in thread "main" javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
    at java.base/sun.security.ssl.Alert.createSSLException(Unknown Source)
    at java.base/sun.security.ssl.Alert.createSSLException(Unknown Source)
    at java.base/sun.security.ssl.TransportContext.fatal(Unknown Source)
    at java.base/sun.security.ssl.Alert$AlertConsumer.consume(Unknown Source)
    at java.base/sun.security.ssl.TransportContext.dispatch(Unknown Source)
    at java.base/sun.security.ssl.SSLTransport.decode(Unknown Source)
    at java.base/sun.security.ssl.SSLSocketImpl.decode(Unknown Source)
    at java.base/sun.security.ssl.SSLSocketImpl.readHandshakeRecord(Unknown Source)
    at java.base/sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
    at java.base/sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
    at java.base/sun.net.www.protocol.https.HttpsClient.afterConnect(Unknown Source)
    at java.base/sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(Unknown Source)
    at java.base/sun.net.www.protocol.https.HttpsURLConnectionImpl.connect(Unknown Source)
    at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:732)
    at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:707)
    at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:297)
    at org.jsoup.helper.HttpConnection.get(HttpConnection.java:286)
    at Scaprefromwikipedia.main(Scaprefromwikipedia.java:19)

Line number 19 is this :-

Document doc = Jsoup.connect("https://en.wikipedia.org/wiki/Java_(programming_language)").get();

I am not able to understand... Why do I get this error?? I have seen somewhere using this piece of code to connect and scrape data from wikipedia but the same is not working for me.

Saurabh Jhunjhunwala
  • 2,832
  • 3
  • 29
  • 57
  • 2
    Does this answer your question? [How to connect via HTTPS using Jsoup?](https://stackoverflow.com/questions/7744075/how-to-connect-via-https-using-jsoup) – chriptus13 Nov 18 '20 at 14:25
  • 1
    Being an secure site you need to import an SSL certificate for it. You can dowload it from your browser. Your question is answered here: https://stackoverflow.com/questions/7744075/how-to-connect-via-https-using-jsoup – JPeter Nov 18 '20 at 14:28
  • Are you using an ancient Java version? It's possible that Wikipedia has switched to a TLS version that's not supported by your Java version. – Joachim Sauer Nov 18 '20 at 14:32
  • As an off-topic side-note: There's almost no good reason to try to scrape from Wikipedia: all of their content is available via database dumps as well as fairly extensive APIs. Pretty much all the information you could want from Wikipedia is easier gotten via means other than scraping. – Joachim Sauer Nov 18 '20 at 14:33
  • @Joachim Sauer it's java 11 – hrishikesh acharyya Nov 18 '20 at 15:27
  • @Joachim Sauer I am scraping Wikipedia because I am learning web scraping and Wikipedia seems to be a nice website to scrape – hrishikesh acharyya Nov 18 '20 at 15:29

0 Answers0