2012-03-06 193 views

回答

4

你可以使用我的lib的.NET Yahoo! Managed。在那裏你有MaasOne.Finance.YahooFinance.CompanyStatisticsDownload類來完成你想要的。

p/s:您需要使用最新版本(0.10.1)。關鍵統計下載已經過時了v0.10.0.2。

+0

這是一個絕對的GEM回答。謝謝!我曾嘗試舊版本的Yahoo! Managed(來自CodeProject - [鏈接](http://www.codeproject.com/Articles/42575/Yahoo-Finance-Managed)),其中測試應用程序中的所有答案都是零或N/A。你給的鏈接完美無缺。抱歉再次打擾你,但是你知道這些方法是否經常需要升級?如果你很忙,不用擔心。我很高興現在能夠獲得這些信息。 – HockeyJ 2012-03-07 23:08:36

+0

不是很常見。這些statisitcs數據不是雅虎官方CSV-API的一部分。相反,lib解析正常的yahoo頁面(通過YQL;所以最終數據來自官方API ^^;這很重要,因爲許可)。所以,每次雅虎改變其網站(表格部分)時,庫都需要更新。 greetz – Maas 2012-03-14 12:10:22

+1

很酷。謝謝(你的)信息。當我獲得報酬時,我會捐贈給這個項目,因爲它真的很棒! – HockeyJ 2012-03-14 13:49:55

4

幾天前我在尋找答案時着手解決了這個問題,想到提供了一個在R中創建的答案(並在R-Bloggers上分享了它)。我知道我提供的答案不在C#中,但每種語言都支持XPath和XML,因此您可以在此處使用此方法。該URL的博客是 - http://www.r-bloggers.com/pull-yahoo-finance-key-statistics-instantaneously-using-xml-and-xpath-in-r/

####################################################################### 
##Alternate method to download all key stats using XML and x_path - PREFERRED WAY 
####################################################################### 

setwd("C:/Users/i827456/Pictures/Blog/Oct-25") 
require(XML) 
require(plyr) 
getKeyStats_xpath <- function(symbol) { 
    yahoo.URL <- "http://finance.yahoo.com/q/ks?s=" 
    html_text <- htmlParse(paste(yahoo.URL, symbol, sep = ""), encoding="UTF-8") 

    #search for <td> nodes anywhere that have class 'yfnc_tablehead1' 
    nodes <- getNodeSet(html_text, "/*//td[@class='yfnc_tablehead1']") 

    if(length(nodes) > 0) { 
    measures <- sapply(nodes, xmlValue) 

    #Clean up the column name 
    measures <- gsub(" *[0-9]*:", "", gsub(" \\(.*?\\)[0-9]*:","", measures)) 

    #Remove dups 
    dups <- which(duplicated(measures)) 
    #print(dups) 
    for(i in 1:length(dups)) 
    measures[dups[i]] = paste(measures[dups[i]], i, sep=" ") 

    #use siblings function to get value 
    values <- sapply(nodes, function(x) xmlValue(getSibling(x))) 

    df <- data.frame(t(values)) 
    colnames(df) <- measures 
    return(df) 
    } else { 
    break 
    } 
} 

tickers <- c("AAPL") 
stats <- ldply(tickers, getKeyStats_xpath) 
rownames(stats) <- tickers 
write.csv(t(stats), "FinancialStats_updated.csv",row.names=TRUE) 

####################################################################### 
+0

這就是屏幕抓圖,速度很慢並且消耗更多的數據 – 2016-04-09 07:35:41

1

如果你不介意使用從BarChart.com關鍵的統計信息,這裏是一個簡單的功能腳本:

library(XML) 

getKeyStats <- function(symbol) { 
    barchart.URL <- "http://www.barchart.com/profile.php?sym=" 
    barchart.URL.Suffix <- "&view=key_statistics" 
    html_table <- readHTMLTable(paste(barchart.URL, symbol, barchart.URL.Suffix, sep = "")) 
    df_keystats = html_table[[5]] 
    print(df_keystats) 
} 
+0

這個網站在倫敦證券交易所似乎沒有股票,但是看起來肯定有一些關於美國股票的相關信息。謝謝。 – HockeyJ 2016-10-30 19:46:23