【发布时间】:2015-06-06 19:12:13
【问题描述】:
我是 Jsoup 的新手,我正在尝试使用以下 html 解析网站,并检索下面 html 中输入的文本的值,特别是“value=14”,然后我想显示该值(在这种情况下,数字 14)作为我的 android 应用程序中文本视图中的字符串。我尝试了多种方法,但没有奏效,我只收到“null”。请举例说明。
<div id="PatientsCurrentlyInClinic" style="display: none"> <!-- Messages are shown when a link with these attributes are clicked: href="#messages" rel="modal" -->
<h3>Which clinic are you updating?</h3>
<form action="" method="get">
<p>
<select name="patientclinicid" id="patientclinicid"><option value="2" selected>Location Two</option><option value="1">Location One</option><option value="3">Location Three</option></select> </p>
<h4>How many patients are in the clinic?</h4>
<p>
To provide better service to your patients, please enter the current number of patients in your clinic.
</p>
<input class="text-input medium-input" type="text" id="small-input" name="patientsInClinic" value="14"/>
<p><input class="button" name="patients-clinic" type="submit" value="Update" /></p>
</form>
</div> <!-- End #messages -->
我给我“null”的尝试如下:
private class Title extends AsyncTask<Void, Void, Void> {
String name;
String value;
@Override
protected void onPreExecute() {
super.onPreExecute();
mProgressDialog = new ProgressDialog(HTML.this);
mProgressDialog.setTitle("Checking Database");
mProgressDialog.setMessage("Loading...");
mProgressDialog.setIndeterminate(false);
mProgressDialog.show();
}
@Override
protected Void doInBackground(Void... params) {
try {
Document doc = Jsoup.connect(url).get();
Elements inputElems =doc.select("input#small-input");
for (Element inputElem : inputElems){
name = inputElem.attr("name");
value = inputElem.attr("value");
}
} catch(Throwable t) {
t.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void result) {
// Set title into TextView
TextView txttitle = (TextView) findViewById(R.id.showPatientNumber);
txttitle.setText(value);
mProgressDialog.dismiss();
}
}
【问题讨论】:
-
做一些事情并提出问题。你可以通过 google-ing 找到一些很好的教程。 androidbegin.com/tutorial/android-basic-jsoup-tutorial
-
我已经尝试过 google-ing 这个解决方案,并且我想出了上面的代码。再次感谢您的帮助。
标签: android html parsing xhtml jsoup