我是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