当前位置: 首页 > 知识库问答 >
问题:

为什么当我试图使用JSOUP在我的类中获取超过1个文档时,我会得到一个handshake_failure错误?

谷梁晟
2023-03-14

似乎每个类只能用Jsoup创建一个get请求,因为当我将CityParkSurl替换为CityParkSurl2时,我放入getParkNames()中的一个会编译,而另一个会出错。

下面是我的代码和错误:

public class DublinCityParksParse{

private final String CITYPARKSURL = "https://www.dublincity.ie/residential/parks/dublin-city-parks/visit-park";
private final String CITYPARKSURL1 = "https://www.dublincity.ie/residential/parks/dublin-city-parks/visit-park?page=1";
private final String CITYPARKSURL2 = "https://www.dublincity.ie/residential/parks/dublin-city-parks/visit-park?page=2";
private final String CITYPARKSURL3 = "https://www.dublincity.ie/residential/parks/dublin-city-parks/visit-park?page=3";

private String[] parkNamesHyphs = {"/eamonn-ceannt-park", "/balcurris"};

private List<String> parkNames = new ArrayList<String>();

private ArrayList<String> parkNamesHyphen = new ArrayList<String>();

private List<Park> parks = new ArrayList<Park>();

public DublinCityParksParse() {
    getParkNames();
    getParkNames1();
}
    
public void getParkNames() {        
    try {       
        Document docGetDetails = Jsoup.connect(CITYPARKSURL).get();
                
        Elements elsClass = docGetDetails.getElementsByClass("search-result__title");

        for(Element els : elsClass) {               
            parkNames.add(els.text());
        }
        
     // System.out.println(docGetDetails.toString());
        System.out.println(parkNames.toString());

    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();        
    }
}

public void getParkNames1() {

    try {       
        Document docGetDetails1 = Jsoup.connect(CITYPARKSURL1).get();
                
        Elements elsClass1 = docGetDetails1.getElementsByClass("search-result__title");

        for(Element els : elsClass1) {              
            parkNames.add(els.text());
        }
        
        System.out.println(docGetDetails1.toString());
        System.out.println(parkNames.toString());

    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    
    }
}

    
public static void main(String[]args) {     
    new DublinCityParksParse();
}} 

错误:

javax.net.ssl.sslhandShakeException:收到致命警报:在java.base/sun.security.ssl.alert.createsslException(alert.java:128)在java.base/sun.security.ssl.alert.createsslException(alert.java:117)在java.base/sun.security.ssl.transportContext.fatal(TransportContext.java.base/sun..ssltransport.decode(ssltransport.java:164)在java.base/sun.security.ssl.sslsocketimpl.decode(sslsocketimpl.java:1152)在java.base/sun.security.ssl.sslsocketimpl.readhandShakeRecord(sslsocketimpl.java:1063)在java.base/sun.AbstractDelegateHttpSurlConnection.Connect(AbstractDelegateHttpSurlConnection.java:185)。base/sun.net.www.protocol.https.httpsurlconnectionimpl.connect(httpsurlconnectionimpl.java:163)在org.jsoup.helper.httpconnection$response.execute(httpconnection.java:732)在org.jsoup.helper.httpconnection.execute(httpconnection.java:707)在org.jsoup.helper.httpconnection.execute(httpconnection.java:297)在dublincityparksparse.java:30)在dublincityparksparse.main(dublincityparksparse.java:182)

共有1个答案

杜绍元
2023-03-14

我敢打赌,您正在IntelliJ和Eclipse之间运行不同的Java版本,而Eclipse版本是旧的(比如1.7或旧的1.8)。这就是为什么它在第一个IDE中工作,而在第二个IDE中不工作。

您应该将JDK更新到当前支持的版本。那些旧版本的Java在当前的TLS/SSL网站上有麻烦。它们缺少了许多密码套件、SNI支持、TLS1.3支持等。您可以为旧版本修补所有这些,但我无法想象您会想要这样做。

 类似资料: