Question

I understand the Jsoup code to retrieve "Stock Name" and "Current Stock Price" from a Yahoo Finance page (e.g. http://finance.yahoo.com/q?s=goog):

String price = doc.select(".time_rtq_ticker").first().text();
String name = doc.select(".title h2").first().text();

But I am not sure how to select other data, for example the Open: or Volume: values.

This is what I have tried so far:

Elements open = doc.getElementsByTag("Open");
Elements volume = doc.getElementsByTag("Volume");
Was it helpful?

Solution

You could get all of the data from the table and then get the correct indexes as separate Elements:

Elements e = doc.select("td.yfnc_tabledata1");
Element open = e.get(1);   // index for open is 1
Element volume = e.get(9); // index for volume is 9

System.out.println("Open: " + open.text());
System.out.println("Volume: " + volume.text());

Will output:

Open: 1,037.16
Volume: 1,613,009

You can't use getElementsByTag("Open") or getElementsByTag("Volume") because those tags don't exist.

OTHER TIPS

I don't sure it return right result but data will contain in :

doc.select("span.time_rtq_ticker");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top