JSOUP 打开url的方式

通常采用这种方式:缓存

        try{
            doc = Jsoup.connect(url)
                .header("User-Agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:49.0) Gecko/20100101 Firefox/49.0")
                .header("Connection", "close")//若是是这种方式,这里务必带上
                .timeout(8000)//超时时间
                .get();
        } catch (Exception e) {//能够精确处理timeoutException
            //超时等异常处理
        }

而我更建议用 URL 去打开post

    //建立请求
    URL url = new URL("https://sms.reyo.cn");
    HttpURLConnection connection = (HttpURLConnection)url.openConnection();
    //默认就是Get,能够采用post,大小写都行,由于源码里都toUpperCase了。
    connection.setRequestMethod("GET");
    //是否容许缓存,默认true。
    connection.setUseCaches(Boolean.FALSE);
    //是否开启输出输入,若是是post使用true。默认是false
    //connection.setDoOutput(Boolean.TRUE);
    //connection.setDoInput(Boolean.TRUE);
    //设置请求头信息
    connection.addRequestProperty("Connection", "close");
    //设置链接主机超时(单位:毫秒)  
    connection.setConnectTimeout(8000);  
     //设置从主机读取数据超时(单位:毫秒)  
    connection.setReadTimeout(8000);    
    //设置Cookie
    connection.addRequestProperty("Cookie","你的Cookies" );
    //开始请求
    Document doc = Jsoup.parse(connection.getInputStream(), "GBK", "https://sms.reyo.cn");
    //开启您的疯狂选择器模式
    doc.select("div.so >div ~ p:eq(10)>:checked");
    //TODO --- 
相关文章
相关标签/搜索