2013-11-28 49 views

回答

2

(1)我湊解決方案

這是一個簡單的答案不包括異常處理線,但是,它是短,制定出框。

public static void main(String[] args) throws IOException { 
      // collect the html and create the doc 
    String url = "http://finance.yahoo.com/q?s=goog"; 
    Document doc = Jsoup.connect(url).get(); 

      // locate the header, title and then found the h2 tag 
    Element header = doc.select("div[id=yfi_rt_quote_summary]").get(0); 
    Element title = header.select("div[class=title]").get(0); 
    String h2 = title.select("h2").get(0).text(); 

      // split by open parenthesis (double escape) and strip off the close parenthesis 
      // TODO - regular expression help handle situation where exist multiple "()"s 
    String[] parts = h2.split("\\("); 
    String name = parts[0]; 
    String shortname = parts[1].replace(")", ""); 
    System.out.println(name); 
    System.out.println(shortname); 

} 

輸出看起來是這樣的:

Google Inc. 
GOOG 

(2)我沒有湊解決方案:

這是真的a nice post您展示如何下載雅虎數據編程。

我也是一個R用戶,它對R內的get Yahoo finance數據非常容易。您可以在那裏進行分析並將其保存到文件或數據庫中(如果需要)。 :)