如何从Android中的HTML链接获取页面的HTML源? [英] How to get the HTML source of a page from a HTML link in Android?

查看:87
本文介绍了如何从Android中的HTML链接获取页面的HTML源?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个应用程序,该应用程序需要从链接获取网页的源,然后解析该页面的html.

I'm working on an application that needs to get the source of a web page from a link, and then parse the html from that page.

您能给我一些例子,还是开始着手编写此类应用程序的起点?

Could you give me some examples, or starting points where to look to start writing such an app?

推荐答案

您可以使用

You can use HttpClient to perform an HTTP GET and retrieve the HTML response, something like this:

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();

这篇关于如何从Android中的HTML链接获取页面的HTML源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆