I need to access a url and pull some information from it. I am using Android Studio. I have code that does not throw any errors, but it is displaying no information. I believe the problem is probably that I am searching for the wrong parameter with my .select statement. Please keep in mind that I am very new to java/android development. Here is my code:
private class FetchAnton extends AsyncTask<Void, Void, Void> {
String price;
String url = "http://www.antoncoop.com/markets/cash.php";
@Override
protected Void doInBackground(Void... params) {
try {
Document document = Jsoup.connect(url).get();
price = String.valueOf(document.select("quotes['KEH15']"));
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void result) {
TextView priceTextView = (TextView) findViewById(R.id.priceTextView);
priceTextView.setText(price);
}
}
And here is the HTML section that the "quotes['KEH15']" refers to (scroll to the right):
</thead>
<tbody>
<script language="javascript">
writeBidRow('Wheat',-60,false,false,false,0.5,'01/15/2015','02/26/2015','All',' ',' ',60,'even','c=2246&l=3519&d=G15',quotes['KEH15'], 0-0);
writeBidRow('Wheat',-65,false,false,false,0.5,'07/01/2015','07/31/2015','All',' ',' ',60,'odd','c=2246&l=3519&d=N15',quotes['KEN15'], 0-0);
</script>
I need to get the value that is represents the "quotes['KEH15']" slot of the html into the string called price. When I run the program, my txt view changes from the default string into a blank. So I think the code is working, but the text view is being updated with a blank string. Can anyone please help me fix this problem?
Thank you for your help.
Keith
quotes['KEH15']section, because it is added by the javascript. Jsoup does not execute the js like your browser would.