2016-11-14 29 views
0

當我嘗試在線URL = forexalgerie.com內得到從表中的數據,我的目標是那些價值:拉數據

enter image description here

..它似乎一切與我的代碼確定:

package marchenoiredinar.qiuworks.com.blackoumla; 

import android.app.ProgressDialog; 
import android.os.AsyncTask; 
import android.os.Bundle; 
import android.support.v7.app.AppCompatActivity; 
import android.view.View; 
import android.widget.Button; 
import android.widget.TextView; 

import org.jsoup.Jsoup; 
import org.jsoup.nodes.Document; 
import org.jsoup.nodes.Element; 
import org.jsoup.select.Elements; 

import java.io.IOException; 

public class MainActivity extends AppCompatActivity { 

Button button; 
TextView textView; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    button = (Button) findViewById(R.id.button); 
    textView = (TextView) findViewById(R.id.textView); 

    button.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      new doIt().execute(); 
     } 
    }); 

} 

public class doIt extends AsyncTask<Void, Void, Void> { 

    String euroSell =""; 
    ProgressDialog mProgressDialog; 

    @Override 
    protected Void doInBackground(Void... params) { 

     try { 
      Document doc =  Jsoup.connect("http://www.forexalgerie.com").get(); 
      Elements els = doc.getElementsByClass("listEvenRow"); 
      for (Element el : els) { 
       euroSell = euroSell + " " + el; 
      } 

     } catch (IOException e) { 
      e.printStackTrace(); 
     } 
     return null; 
    } 

    @Override 
    protected void onPostExecute(Void aVoid) { 
     super.onPostExecute(aVoid); 
     textView.setText(euroSell); 
     mProgressDialog.dismiss(); 
    } 

    @Override 
    protected void onPreExecute() { 
     super.onPreExecute(); 
     mProgressDialog = new ProgressDialog(MainActivity.this); 
     mProgressDialog.setTitle("Android Jsoup ListView Tutorial"); 
     mProgressDialog.setMessage("Loading..."); 
     mProgressDialog.setIndeterminate(false); 
     mProgressDialog.show(); 
    } 
} 
} 

但是..結果包含表中的所有內容,除了我想要的值?

enter image description here

有什麼不對?

+0

試'euroSell = euroSell + 「」 + el.html();'代替'euroSell = euroSell + 「」 + EL;' –

回答

0

嘗試的euroSell = euroSell + " " + el.id()代替euroSell = euroSell + " " + el

try { 
    Document doc = Jsoup.connect("http://www.forexalgerie.com").get(); 
    Elements els = doc.getElementsByClass("listEvenRow"); 
    for (Element el : els) { 
     euroSell = euroSell + " " + el.id(); 
    } 
} catch (IOException e) { 
    e.printStackTrace(); 
}