我想从网站http://www.mtn.co.ug/Mobile-Plans/PayAsYouGo/MTN-PerMinute.aspx检索表中包含的数据并将其用于 android 应用程序,以便在更新时,信息在应用程序中也更新了。但是,我对android不是很熟悉。所以我需要帮助来使用 htmlcleaner 和 jsoup/json 检索数据。
谢谢。
我想从网站http://www.mtn.co.ug/Mobile-Plans/PayAsYouGo/MTN-PerMinute.aspx检索表中包含的数据并将其用于 android 应用程序,以便在更新时,信息在应用程序中也更新了。但是,我对android不是很熟悉。所以我需要帮助来使用 htmlcleaner 和 jsoup/json 检索数据。
谢谢。
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;
}
}
MTN 大声笑。在尼日利亚使用它。下面是一个示例,假设您已经了解 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());
}
祝你好运