如何从Android中一个HTML链接的HTML代码的网页吗?代码、链接、网页、Android

由网友(七个字)分享简介:我工作,需要从一个链接的网页的源,然后解析来自该网页的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 p...

我工作,需要从一个链接的网页的源,然后解析来自该网页的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?

推荐答案

您可以使用HttpClient执行HTTP GET和检索HTML的响应,是这样的:

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();
阅读全文

相关推荐

最新文章