我正在使用
Boilerpipe从url中提取文本,使用以下代码:
URL url = new URL("http://www.example.com/some-location/index.html"); String text = ArticleExtractor.INSTANCE.getText(url);
解决方法
对于像这样简单的事情,你真的不需要一个外部库:
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();