我正在开发一个需要从链接获取网页源,然后从该页面解析html的应用程序。
您能给我一些例子,还是从哪里着手开始编写这样的应用程序?
您可以使用HttpClient执行HTTP GET并检索HTML响应,如下所示:
HttpClient client = new DefaultHttpClient(); HttpGet request = new HttpGet(url); HttpResponse response = client.execute(request); String html = ""; InputStream in = response.getEntity().getContent(); BufferedReader reader = new BufferedReader(new InputStreamReader(in)); StringBuilder str = new StringBuilder(); String line = null; while((line = reader.readLine()) != null) { str.append(line); } in.close(); html = str.toString();