Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>to read-in the financial information try this function ( I picked it up several months ago and made some small adjustments)</p> <pre><code>require(XML) require(plyr) getKeyStats_xpath &lt;- function(symbol) { yahoo.URL &lt;- "http://finance.yahoo.com/q/ks?s=" html_text &lt;- htmlParse(paste(yahoo.URL, symbol, sep = ""), encoding="UTF-8") #search for &lt;td&gt; nodes anywhere that have class 'yfnc_tablehead1' nodes &lt;- getNodeSet(html_text, "/*//td[@class='yfnc_tablehead1']") if(length(nodes) &gt; 0 ) { measures &lt;- sapply(nodes, xmlValue) #Clean up the column name measures &lt;- gsub(" *[0-9]*:", "", gsub(" \\(.*?\\)[0-9]*:","", measures)) #Remove dups dups &lt;- 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 &lt;- sapply(nodes, function(x) xmlValue(getSibling(x))) df &lt;- data.frame(t(values)) colnames(df) &lt;- measures return(df) } else { break } } </code></pre> <p>to use it, compare for example 3 companies and write the data into a csv-file do the following:</p> <pre><code>tickers &lt;- c("AAPL","GOOG","F") stats &lt;- ldply(tickers, getKeyStats_xpath) rownames(stats) &lt;- tickers write.csv(t(stats), "FinancialStats_updated.csv",row.names=TRUE) </code></pre> <p>Just tried it. Still working.</p> <p>UPDATE as Yahoo changed it’s web site layout:</p> <p>The function above does not work anymore as Yahoo again changed its web site layout. Fortunately its still easy to get the financial infos as the tags for getting fundamental data have not been changed. example for downloading a file with eps and P/E ratio for MSFT, AAPL and Ford insert the following into your browser:</p> <pre><code>http://finance.yahoo.com/d/quotes.csv?s=MSFT+AAPL+F&amp;f=ser </code></pre> <p>and after entering the above URL into your browser’s address bar and hitting return/enter. The CSV will be automatically downloaded to your computer and you should get the cvs file as shown below (data as 7/22/2016):</p> <p><a href="https://i.stack.imgur.com/UDlq6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/UDlq6.png" alt="enter image description here"></a></p> <p>some yahoo tags for fundamental data:</p> <p><a href="https://i.stack.imgur.com/9k5sg.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9k5sg.png" alt="enter image description here"></a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload