作者Magicx (270度的鳥顧之相)
看板AndroidDev
標題[問題] 請問如何擷取網頁資料作處理
時間Thu Sep 1 00:16:24 2011
最近想寫個讓程式擷取網頁原始碼資料並SHOW在TEXTVIEW已確定動作有成功~
參考網路上許多相關CODE發現有用HTTPURLCONNECT的..HTTPPOST的..
後來覺得這個寫法似乎比較簡潔...可是不知道為何都沒有反應...
請問是哪裡有問題呢?? 感謝指教~~
TextView getwebdata = (TextView) findViewById (R.id.getdata);
String savegetwebdata =getwebdata.getText().toString();
try {
HttpClient hc = new DefaultHttpClient();
HttpGet get = new HttpGet("
http://www.google.com");
HttpResponse echo = hc.execute(get);
if (echo.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
//getwebdata.setText(savegetwebdata+"HttpStatus SC_OK" );
InputStream is = echo.getEntity().getContent();
//savegetwebdata =getwebdata.getText().toString();
getwebdata.setText(savegetwebdata+is );
}
} catch (Exception e) {
// TODO: handle exception
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 114.34.226.28
1F:推 ericinttu:是什麼沒有反應? 09/01 10:37
2F:→ Magicx:textview沒有顯示出網頁回傳資料 09/01 19:18
4F:推 minksable:直接丟InputStream要TextView顯示應該行不通吧? 09/02 13:53