在JSoup 1.8.2中使用兄弟姐妹索引的问题

时间:2015-08-28 01:19:19

标签: java jsoup

Java新手。尝试学习/练习JSoup。

目标:提取"关闭"来自雅虎财经的历史价格专栏。

以下代码同时返回"关闭"价格和" Adj Close"价格。

" S"以下是SP 500中的任何股票代码。

发现了我作为模特使用过的另一篇文章。 (这里:How to parse the cells of the 3rd column of a table?)。

public class MovingAverage200 {

private String ticker;
private String movingAverageURL;
double movingAverage200;

public MovingAverage200(String s)   {

    ticker = s;
    movingAverageURL = ("https://finance.yahoo.com/q/hp?s="+ticker+"+Historical+Prices");

}

public void setMovingAverage()  {

    try {
        Document document = Jsoup.connect(movingAverageURL).get();
        Elements prices = document.select("td.yfnc_tabledata1:eq(4)");

        for (Element price : prices) {
            System.out.println(price.text());
        }

    }
    catch (IOException ex)  {
        ex.printStackTrace();
    }
}

1 个答案:

答案 0 :(得分:0)

alkis发布的提示:

  

如果您使用的是先前版本(1.8.2),则只需使用最新版本。有一些性能调整引入了有关兄弟姐妹的错误。