【发布时间】:2015-04-09 17:09:25
【问题描述】:
这是我在这里的第一篇文章。我是业余爱好者,请多多包涵。
我正在尝试使用以下代码从https://eztv.it/shows/1/24/ 抓取网页。
public static void WriteHTMLToFile(String URL){
try {
URI myURI=new URI(URL);
URL url = myURI.toURL();
HttpsURLConnection con= (HttpsURLConnection)url.openConnection();
File myFile=new File("c:\\project\\Test.txt");
myFile.createNewFile();
FileWriter wr=new FileWriter(myFile);
InputStream ins=con.getInputStream();
InputStreamReader isr= new InputStreamReader(ins);
BufferedReader reader = new BufferedReader(isr);
String line;
while ((line = reader.readLine()) != null) {
wr.write(line+"\n");
}
reader.close();
wr.close();
}
catch(Exception e){
log(e.toString());
}
}
当我运行它时,我得到以下信息:
javax.net.ssl.SSLException: SSL peer 错误关闭
如果我在此 URL 上运行上述代码:https://eztv.it/shows/887/the-blacklist/,它会按预期工作。两个 URL 文件大小之间的差异似乎是一个促成因素。在测试到同一服务器的不同 URL 时,上面的代码似乎只适用于小于 ~30Kb 的文件。任何超过都会产生上述异常。
【问题讨论】: