I am using jsoup to extract data from a table in a website.http://www.moneycontrol.com/stocks/marketstats/gainerloser.php?optex=BSE&opttopic=topgainers&index=-1 using Jsoup. I have referred to Using JSoup To Extract HTML Table Contents and other similar questions but it does not print the data. Could someone please provide me with the code required to achieve this?
public class TestClass { public static void main(String args[]) throws IOException { Document doc = Jsoup.connect("http://www.moneycontrol.com/stocks/marketstats/gainerloser.php?optex=BSE&opttopic=topgainers&index=-1").get(); for (Element table : doc.select("table.tablehead")) { for (Element row : table.select("tr")) { Elements tds = row.select("td"); if (tds.size() > 6) { System.out.println(tds.get(0).text() + ":" + tds.get(1).text()); } } }
If you want to get the content of table(not head), you need change the selector of table:
for (Element table : doc.select("table.tbldata14"))
instead of
for (Element table : doc.select("table.tablehead"))
1.4m articles
1.4m replys
5 comments
57.0k users