从网页上的表(类)中检索数据,以便在android中使用

时间:2014-03-13 18:22:23

标签: android json jsoup htmlcleaner

我想从网站http://www.mtn.co.ug/Mobile-Plans/PayAsYouGo/MTN-PerMinute.aspx检索表中包含的数据,并在Android应用程序中使用它,以便在更新时,应用程序中的信息也会更新。但是,我并不熟悉android。所以我需要帮助来使用htmlcleaner和jsoup / json检索数据。

感谢名单。

2 个答案:

答案 0 :(得分:0)

MTN yello lol。在尼日利亚使用它。下面是一个关于如何做的示例,假设您已经知道了Android,那么您需要转到http://jsoup.org/cookbook/以了解有关jsoup库的更多信息

 TextView textView;
    Document doc = Jsoup.connect("http://www.mtn.co.ug/Mobile-Plans/PayAsYouGo/MTN-PerMinute.aspx").timeout(90000)
                                .ignoreHttpErrors(true).get();

        for (Element Yello: doc.select("div tbody:contains(Bundle):eq(6) tr td") )) {

    textView.setText(Yello.text());

                        }

祝你好运

答案 1 :(得分:0)

public class MainActivity extends Activity {

TextView tv; final String URL = "http://www.mtn.co.ug/Mobile-Plans/PayAsYouGo/MTN-PerMinute.aspx";

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    tv = (TextView) findViewById(R.id.textView);
    new MyTask().execute(URL);
}

private class MyTask extends AsyncTask<String, Void, String> {
    ProgressDialog prog;
    String title = "";
    @Override
    protected void onPreExecute() {
        prog = new ProgressDialog(MainActivity.this);
        prog.setMessage("Loading....");
        prog.show();
    }
    @Override   
    protected String doInBackground(String... params) {
        try {
            Document Doc= Jsoup.connect(params[0]).get();
            //timeout(90000).ignoreHttpErrors(true);

            //title = Doc.title();
            for (Element Yello: Doc.select("div tbody:contains(Bundle):eq(6) tr td") ) {

                System.out.println(Yello.text());
                tv.setText(Yello.text());

                title = Yello.toString();
                                    }
        } catch (IOException e) {

            e.printStackTrace();
        }
        return null;
    }
    @Override
    protected void onPostExecute(String result) {
        super.onPostExecute(result);

        tv.setText(title);
        prog.dismiss();
    }
        }
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

}