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

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

本文介绍了如何从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?

推荐答案

您可以使用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();

这篇关于如何从Android中一个HTML链接的HTML代码的网页吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 00:55