【发布时间】:2014-10-13 23:31:39
【问题描述】:
尝试从网站中提取标题,打印标题时出现流关闭错误。试图在标题标签之间提取,例如 .不熟悉机智解析请在解释时彻底。谢谢。
import java.lang.*;
import java.util.Scanner;
import java.net.*;
import java.io.*;
public class Allrecipes{
public static void main(String[] args) throws Exception{
System.out.println("Colby Mehmen");
Scanner input = new Scanner(System.in);
String str1 = "";
str1 = compare();
if (str1.contains("http://allrecipes.com")){
URL oracle = new URL(str1);
BufferedReader in = new BufferedReader(
new InputStreamReader(oracle.openStream()));
String html;
while ((html = in.readLine()) != null)
in.close();
String page = html;
int start = page.indexOf("<title>");
int end = page.indexOf("</title>");
String title = page.substring(start+"<title>".length(),end);
System.out.println(title);
}//end program
}
【问题讨论】:
-
如果你能格式化你的代码就好了。
-
@SotiriosDelimanolis 很抱歉,稍微清理一下
-
java.io.IOException: 流关闭
-
^ 我现在收到的错误
-
查看我的更新答案,如果您接受该答案将不胜感激
标签: java html parsing bufferedreader