我是Jsoup的新手,我试图用下面的html解析一个网站,并在下面的html中检索文本输入的值,特别是我想要的“value = 14”在我的android应用程序的文本视图中显示该值(在这种情况下数字14)作为字符串。我尝试了多种方式,但它没有奏效,我只收到“null”。请举例说明。Jsoup解析HTML问题
<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 -->
我的尝试,让我“空”如下:
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找到一些很好的教程。 http://www.androidbegin.com/tutorial/android-basic-jsoup-tutorial/ – dare 2015-04-01 23:52:26
我已经尝试谷歌这个解决方案,我已经拿出了上面的代码。再次感谢任何帮助。 – Manu 2015-04-01 23:56:33