本文介绍了从网站作为字符串加载数据(安卓)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道如何使用的WebView加载在Android的网站的内容(webview.loadUrl(http://slashdot.org/);)
I know how to load site's content in Android using WebView (webview.loadUrl("http://slashdot.org/");)
和我怎么可以把网站的内容的字符串变量(后我想解析这个字符串以XML,但是这是接下来的一点改进)
And how can I put site's content in String variable(After I'd like to parse this string to XML but this is next problen)
推荐答案
下面是一个务实的回答你的问题:
Here is a pragmatical answer to your question:
HttpClient httpClient = new DefaultHttpClient();
HttpContext localContext = new BasicHttpContext();
HttpGet httpGet = new HttpGet("http://www.spartanjava.com");
HttpResponse response = httpClient.execute(httpGet, localContext);
String result = "";
BufferedReader reader = new BufferedReader(
new InputStreamReader(
response.getEntity().getContent()
)
);
String line = null;
while ((line = reader.readLine()) != null){
result += line + "\n";
}
// Now you have the whole HTML loaded on the result variable
http://www.spartanjava.com / 2009 / GET-A-网页-编程 - 从 - 安卓/
这篇关于从网站作为字符串加载数据(安卓)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!