2013-12-20 64 views
-1

我在Java的這個請求,但是在響應我所擁有的一切來源,JSON對象失敗..請求在java中獲取GET HTML源

HttpClient client = new DefaultHttpClient(); 

     HttpGet request = new HttpGet(
       "http://url?"+params); 
     HttpResponse response = client.execute(request); 
     BufferedReader rd = new BufferedReader(
       new InputStreamReader(response.getEntity().getContent())); 

      StringBuffer result = new StringBuffer(); 
      String line = ""; 
      while ((line = rd.readLine()) != null) { 
       result.append(line); 
      } 


     String str = result.toString(); 

Document doc = Jsoup.parse(str); 

     JSONObject json = new JSONObject(); 


     List<JSONObject> list = new ArrayList<JSONObject>(); 


     Element elementsTable = doc.getElementById("shortlist"); 

這個元素名單無法找到。 。但如果我去我的瀏覽器,並得到源的地方是......我錯了?

+4

請你的問題更清楚了嗎? – Deepak

+0

什麼「r」在做什麼? –

+0

我想要來自url請求的源代碼。如果我在瀏覽器中查看它的工作原理,我會看到源代碼,並在源代碼中有一個id = shortlist的表格。所以我嘗試在Java中獲得這個源代碼,但不能以我的方式工作 – FelasDroid

回答

-1

您可以用Jsoup簡單的代碼做...

Connection connection = Jsoup.connect(url) 
Document urlDoc = connection.get(); 
Elements domElement = urlDoc.getElementById(String id);