綁定帳號登入

Android 台灣中文網

打印 上一主題 下一主題

[求助] 讀取XML抓不到資料

[複製連結] 查看: 1057|回覆: 4|好評: 0
跳轉到指定樓層
樓主
sfzvzfbv | 收聽TA | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
發表於 2016-1-22 17:45

馬上加入Android 台灣中文網,立即免費下載應用遊戲。

您需要 登錄 才可以下載或查看,沒有帳號?註冊

x
我要抓取政府的OpenData資料庫的XML,但是始終抓不到資料,不知道是不是連線的程式碼有問題,請教各位前輩。

  1. private static InputStream connect() {
  2.         HttpURLConnection urlConnection = null;
  3.         InputStream inputStream = null;
  4.         try {
  5.             URL url = new URL("http://opendata2.epa.gov.tw/AQX.xml");
  6.             urlConnection = (HttpURLConnection) url.openConnection();
  7.             urlConnection.setReadTimeout(10000);
  8.             urlConnection.setConnectTimeout(15000);
  9.             urlConnection.setRequestMethod("GET");
  10.             urlConnection.connect();
  11.             inputStream = new BufferedInputStream(urlConnection.getInputStream());
  12.         } catch (MalformedURLException e) {
  13.             e.printStackTrace();
  14.         } catch (IOException e) {
  15.             e.printStackTrace();
  16.         } catch (Exception e) {
  17.             e.getMessage();
  18.         } finally {
  19.             assert urlConnection != null;
  20.             urlConnection.disconnect();
  21.         }
  22.         return inputStream;
  23.     }
複製代碼
「用Android 就來APK.TW」,快來加入粉絲吧!
Android 台灣中文網(APK.TW)
收藏收藏 分享分享 分享專題
用Android 就來Android 台灣中文網(https://apk.tw)
回覆

使用道具 舉報

沙發
whl | 收聽TA | 只看該作者
發表於 2016-1-23 20:42
可能的問題點太多了,為何不貼 log 來看?
用Android 就來Android 台灣中文網(https://apk.tw)
回覆 支持 反對

使用道具 舉報

板凳
 樓主| sfzvzfbv | 收聽TA | 只看該作者
發表於 2016-1-23 23:31
whl 發表於 2016-1-23 20:42
可能的問題點太多了,為何不貼 log 來看?


程式沒有出現任何錯誤,只是抓不到網路資料,上面是連線到網路的程式碼,我只是想問上面的程式碼有沒有錯誤而已。
用Android 就來Android 台灣中文網(https://apk.tw)
回覆 支持 反對

使用道具 舉報

地板
NekoRin | 收聽TA | 只看該作者
發表於 2016-2-7 20:44
由 手機網頁 發佈
URL的位址是否正確??
用Android 就來Android 台灣中文網(https://apk.tw)
回覆 支持 反對

使用道具 舉報

5
x3093410155 | 收聽TA | 只看該作者
發表於 2016-3-14 23:38
本帖最後由 x3093410155 於 2016-3-14 23:40 編輯

我大概知道你在GET網頁 之後的代碼就不知道了 因為我不是C#的程序員

你是要把資料全部都套出來之後顯示在軟件上面嗎?
如果是這樣就要用正則匹配資料
用Android 就來Android 台灣中文網(https://apk.tw)
回覆 支持 反對

使用道具 舉報

您需要登錄後才可以回帖 登錄 | 註冊

本版積分規則