java—当我尝试使用jsoup获取类中的多个文档时,为什么会出现握手失败错误?

7gyucuyw  于 2021-07-03  发布在  Java
关注(0)|答案(1)|浏览(409)

似乎每个类只能用jsoup创建一个get请求,因为 CITYPARKSURL 为了 CITYPARKSURL2 ,我放进去的那个 getParkNames() 编译,另一个给出错误。
我在intellij中运行了这段代码,但是当我把它移到eclipse中时,它开始给我这些握手错误。有人知道这是为什么吗(不幸的是,我不得不在eclipse中完成我的项目。)
以下是我的代码和错误:

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(警报)处收到致命警报:握手失败。java:128)在java.base/sun.security.ssl.alert.createsslexception(alert。java:117)在java.base/sun.security.ssl.transportcontext.fatal(transportcontext。java:308)在java.base/sun.security.ssl.alert$alertconsumer.consume(警报。java:279)在java.base/sun.security.ssl.transportcontext.dispatch(transportcontext。java:181)在java.base/sun.security.ssl.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.security.ssl.sslsocketimpl.startAndShake(sslsocketimpl。java:402)位于java.base/sun.net。www.protocol.https.httpsclient.afterconnect(httpsclient。java:567)在java.base/sun.net。www.protocol.https.abstractdelegatehttpsurlconnection.connect(abstractdelegatehttpsurlconnection。java:185)位于java.base/sun.net。www.protocol.https.httpsurlconnectionimpl.connect(httpsurlconnectionimpl。java:163)在org.jsoup.helper.httpconnection$response.execute(httpconnection。java:732)在org.jsoup.helper.httpconnection$response.execute(httpconnection。java:707)在org.jsoup.helper.httpconnection.execute(httpconnection。java:297)在org.jsoup.helper.httpconnection.get(httpconnection。java:286)在都柏林城市公园公园1(都柏林城市公园公园)。java:68)都柏林城市公园。java:30)在main(都柏林城市公园)。java:182)

ep6jt1vc

ep6jt1vc1#

我打赌您在intellij和eclipse之间运行不同的java版本,而eclipse版本是旧的(比如1.7或旧的1.8)。这就是为什么它在第一个ide中工作,而不是在第二个ide中。
您应该将jdk更新到当前支持的版本。那些旧版本的java与当前的tls/ssl网站有问题。他们缺少许多密码套件,sni支持,tls1.3支持,等等。你可以在旧版本中修补所有这些,但我无法想象你会想这么做。

相关问题