I am new to Jsoup and am trying to parse a website, with the following html, and retrieve the value of the text input in the html below, specifically the "value=14" which I then want to display that value (the number 14 in this case) as a string in a text view in my android app. I have tried multiple ways but it hasn't worked, I just receive "null". Please show example.
<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 -->
My attempt that gives me "null" is as follows:
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();
}
}