当我尝试从在线URL = forexalgerie.com中的表中获取数据时,我的目标是这些值:
..似乎我的代码一切正常:
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();
}
}
}
但是...结果包含表格内的所有内容,除了我想要的值?
有什么问题?
答案 0 :(得分: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();
}