Android Question JSoup and Element siblings

mrushdi

Member
Licensed User
Longtime User
please help on how to get element siblings or in using the following java code (try/catch block) in B4A project


import android.os.AsyncTask;
import io.fabric.sdk.android.services.common.AbstractSpiCall;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Element;

public class AaibSpider extends AsyncTask<BankDelegate, Integer, BankResult> {
BankDelegate delegate;

protected BankResult doInBackground(BankDelegate... delegates) {
String bankName = AaibSpider2.BANK_NAME;
try {
this.delegate = delegates[0];
Element elemnt = Jsoup.connect("http://aaib.com/ar/rates").timeout(AbstractSpiCall.DEFAULT_TIMEOUT).get().select("td:contains(US DOLLAR)").first();
BankResult bankResult = new BankResult();
bankResult.buyingPrice = Double.parseDouble(((Element) elemnt.siblingElements().get(0)).text());
bankResult.sellingPrice = Double.parseDouble(((Element) elemnt.siblingElements().get(1)).text());
bankResult.bankName = AaibSpider2.BANK_NAME;
return bankResult;
} catch (Exception e) {
e.printStackTrace();
delegates[0].onBankError(AaibSpider2.BANK_NAME);
return null;
}
}

protected void onPostExecute(BankResult s) {
super.onPostExecute(s);
if (s != null) {
this.delegate.onBankResult(s);
}
}
}
 
Top