我正在使用Java从网页中获取一大块HTML。现在我正在使用带有getInputStream()的URLConnection,它正在加载整个页面并花费比我想要的时间更长的时间。无论如何,它只是加载我需要的块或排除图像或其他任何可以加速的块。任何帮助表示赞赏。谢谢。加快HTML提取速度
下面是一些代码:
URL page = new URL("http://www.stackoverflow.com");
URLConnection connection = page.openConnection();
String html = getResponseData(connection);
public static String getResponseData(URLConncetion connection) {
StringBuffer sb = new StringBuffer();
InputStream is = connection.getInputStream();
int count;
while((count=is.read()) != -1){
sb.append((char)count);
}
有一些示例代码? – MadProgrammer 2012-08-01 14:38:05