从URL中提取HTML

Was*_*RAR 7 html java string url extract

我正在使用Boilerpipe从url中提取文本,使用以下代码:

URL url = new URL("http://www.example.com/some-location/index.html");
String text = ArticleExtractor.INSTANCE.getText(url);
Run Code Online (Sandbox Code Playgroud)

String text只包含html页面的文本,但我需要从中提取整个html代码.

是否有人使用此库并知道如何提取HTML代码?

您可以查看演示页面以获取有关库的更多信息.

Gor*_*vic 10

对于像这样简单的事情,你真的不需要一个外部库:

 URL url = new URL("http://www.google.com");
 InputStream is = (InputStream) url.getContent();
 BufferedReader br = new BufferedReader(new InputStreamReader(is));
 String line = null;
 StringBuffer sb = new StringBuffer();
 while((line = br.readLine()) != null){
   sb.append(line);
 }
 String htmlContent = sb.toString();
Run Code Online (Sandbox Code Playgroud)