我正在使用jsoup从网站中的表中提取数据。 http://www.moneycontrol.com/stocks/marketstats/gainerloser.php?optex=BSE&opttopic=topgainers&index=-1使用Jsoup。我提到Using JSoup To Extract HTML Table Contents和其他类似的问题,但它不打印数据。有人可以请我提供实现此目标所需的代码吗?使用Jsoup提取数据
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());
}
}
}
这可能有助于查看您的代码以帮助您。 .. – quaylar 2012-02-20 09:30:59
[使用条款](http://www.moneycontrol.com/cdata/termsofuse.php)表明,未经moneycontrol.com明确书面许可,不得允许此类行为。如果您有权限,请向他们询问关于访问数据的首选API(由他们组织)。例如。我注意到其中一个链接提到RSS提要。这是比HTML更“机器友好”的信息形式。 – 2012-02-20 09:39:30
我想获得表格中涨幅居前的名字。我不得不稍微调整代码,但不知道我必须做什么,因为我是jsoup的新手。 – user1092042 2012-02-20 13:00:17