2013-11-28 108 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数据非常容易。您可以在那里进行分析并将其保存到文件或数据库中(如果需要)。 :)