Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Finance.yahoo scraper - keystats + financial statements - v0.1 #309

Merged
merged 251 commits into from

2 participants

canada4663 Paul Donnelly
canada4663

yahoo keystats, income statements, cash flow, and balance sheet working

canada4663 added some commits
canada4663 canada4663 Added yahoo/finance/balancesheet_dev/yahoo.finance.balancesheet_dev.x…
…ml (unfiltered) via YQL Table Editor
99e8388
canada4663 canada4663 Added yahoo/finance/balancesheet_dev/yahoo.finance.balancesheet_dev.x…
…ml (unfiltered) via YQL Table Editor
0766ef0
canada4663 canada4663 Added yahoo/finance/balancesheet_dev/yahoo.finance.balancesheet_dev.x…
…ml (unfiltered) via YQL Table Editor
866eaab
canada4663 canada4663 Revert "Added yahoo/finance/balancesheet_dev/yahoo.finance.balanceshe…
…et_dev.xml (unfiltered) via YQL Table Editor"

This reverts commit 866eaab.
d5f6691
canada4663 canada4663 Revert "Revert "Added yahoo/finance/balancesheet_dev/yahoo.finance.ba…
…lancesheet_dev.xml (unfiltered) via YQL Table Editor""

This reverts commit d5f6691.
5dadfdd
canada4663 canada4663 Revert "Added yahoo/finance/balancesheet_dev/yahoo.finance.balanceshe…
…et_dev.xml (unfiltered) via YQL Table Editor"

This reverts commit 866eaab.
f52c72e
canada4663 canada4663 Revert "Revert "Added yahoo/finance/balancesheet_dev/yahoo.finance.ba…
…lancesheet_dev.xml (unfiltered) via YQL Table Editor""

This reverts commit d5f6691.
04d7df7
canada4663 canada4663 Test 0da46be
canada4663 canada4663 Test 243729f
canada4663 canada4663 Added yahoo/finance/quote_test/yahoo.finance.quote_test.xml (unfilter…
…ed) via YQL Table Editor
6afcb80
canada4663 canada4663 start balancesheet.xml development a892948
canada4663 canada4663 ... 8fdda16
canada4663 canada4663 Balancesheet dev 0157c79
canada4663 canada4663 . fdae291
canada4663 canada4663 Merge remote-tracking branch 'upstream/master' ad6bfbf
canada4663 canada4663 test 4dccce9
canada4663 canada4663 test2 009b88b
canada4663 canada4663 test3 37bbf67
canada4663 canada4663 Revert "test3"
This reverts commit 37bbf67.
554d761
canada4663 canada4663 Revert "Revert "test3""
This reverts commit 554d761.
d91182f
canada4663 canada4663 Revert "Revert "Revert "test3"""
This reverts commit d91182f.
36160dc
canada4663 canada4663 Revert "Revert "test3""
This reverts commit 554d761.
e3a4306
canada4663 canada4663 Revert "test3"
This reverts commit 37bbf67.
09dcf31
canada4663 canada4663 Revert "test2"
This reverts commit 009b88b.
b85fb2a
canada4663 canada4663 add key stats 616ca77
canada4663 canada4663 Added yql-console info for devel 5d582f2
canada4663 canada4663 Add yahoo.finance.com information for development c79adbf
canada4663 canada4663 keystats dev 2efd268
canada4663 canada4663 d fb66228
canada4663 canada4663 t eeff6fc
canada4663 canada4663 t 427079d
canada4663 canada4663 t 65a704a
canada4663 canada4663 t 136f94c
canada4663 canada4663 t 92c2c51
canada4663 canada4663 t 5032dc7
canada4663 canada4663 t 761096e
canada4663 canada4663 t 4562e2f
canada4663 canada4663 t c7cc3b0
canada4663 canada4663 t 2dd25a3
canada4663 canada4663 t 53b91d6
canada4663 canada4663 t e49e959
canada4663 canada4663 t 05c4c25
canada4663 canada4663 t 06d7187
canada4663 canada4663 t 645ac4d
canada4663 canada4663 t 1b7c070
canada4663 canada4663 t 9017b46
canada4663 canada4663 t f697fb2
canada4663 canada4663 t 5347cb9
canada4663 canada4663 t 9f91396
canada4663 canada4663 t afb510b
canada4663 canada4663 t 4557e5a
canada4663 canada4663 t 66a61a7
canada4663 canada4663 t bd839a4
canada4663 canada4663 t 8584ef0
canada4663 canada4663 t d0bf525
canada4663 canada4663 t b9bed7e
canada4663 canada4663 t 42afb18
canada4663 canada4663 t 294c554
canada4663 canada4663 t f031029
canada4663 canada4663 t 682fbc6
canada4663 canada4663 t 38be5b3
canada4663 canada4663 t 37d7425
canada4663 canada4663 tt eafafa2
canada4663 canada4663 t 294a29f
canada4663 canada4663 t 4b647ea
canada4663 canada4663 t d0ad791
canada4663 canada4663 t c30fe2e
canada4663 canada4663 t be0d3c3
canada4663 canada4663 t 6874a7b
canada4663 canada4663 t 08e0cff
canada4663 canada4663 t 846250d
canada4663 canada4663 t 48cc8d1
canada4663 canada4663 t 96e9d5c
canada4663 canada4663 t 35b5565
canada4663 canada4663 keystats2 - enable rollback to working version of keystats 7c2d3a5
canada4663 canada4663 Revert "keystats2 - enable rollback to working version of keystats"
This reverts commit 7c2d3a5.
c528a55
canada4663 canada4663 Revert "t"
This reverts commit 35b5565.
f514498
canada4663 canada4663 keystats2 cacfeec
canada4663 canada4663 t 54b7689
canada4663 canada4663 t d6c3a66
canada4663 canada4663 t dcb986c
canada4663 canada4663 t e7fa396
canada4663 canada4663 t 32961c6
canada4663 canada4663 t a9356db
canada4663 canada4663 t b35c763
canada4663 canada4663 t a6fae57
canada4663 canada4663 t c9926b1
canada4663 canada4663 t 372839b
canada4663 canada4663 t 483eaf9
canada4663 canada4663 t f03260f
canada4663 canada4663 t 394e602
canada4663 canada4663 t b9e29b7
canada4663 canada4663 t 7e4ef73
canada4663 canada4663 t b3aa29f
canada4663 canada4663 t 2080390
canada4663 canada4663 t 4cb0265
canada4663 canada4663 t d875643
canada4663 canada4663 t 809f300
canada4663 canada4663 t 385f026
canada4663 canada4663 t 5b0e8c0
canada4663 canada4663 t 0bae10c
canada4663 canada4663 t c3ec13d
canada4663 canada4663 t 9b1387b
canada4663 canada4663 t 51b586b
canada4663 canada4663 t 082dd83
canada4663 canada4663 t f951e72
canada4663 canada4663 t e6b4fd6
canada4663 canada4663 t fc6576e
canada4663 canada4663 t 352c9b6
canada4663 canada4663 t 3eb18a3
canada4663 canada4663 t 3473812
canada4663 canada4663 t 27a48fa
canada4663 canada4663 Stable - Remaining Minor Bugs 75688ed
canada4663 canada4663 Stable - Minor Bugs Remain cf3c65b
canada4663 canada4663 s 317a05d
canada4663 canada4663 s bfe82ac
canada4663 canada4663 s bf04f12
canada4663 canada4663 s 388e879
canada4663 canada4663 s 67791f9
canada4663 canada4663 s e2c8d62
canada4663 canada4663 s 200bdc1
canada4663 canada4663 s 46a3be8
canada4663 canada4663 s 5950bb4
canada4663 canada4663 s 04e8ad8
canada4663 canada4663 s 6605e9d
canada4663 canada4663 Baseline - Working 023100b
canada4663 canada4663 t b2bd3a9
canada4663 canada4663 t c179161
canada4663 canada4663 t 3eb3c92
canada4663 canada4663 t 5395233
canada4663 canada4663 t f0230fe
canada4663 canada4663 t 497a7cd
canada4663 canada4663 t 60c2b97
canada4663 canada4663 t 718cb1b
canada4663 canada4663 t 500cb7a
canada4663 canada4663 t faaf7fb
canada4663 canada4663 t a2a8fd5
canada4663 canada4663 t 2b9de91
canada4663 canada4663 x b1f63f4
canada4663 canada4663 x cdca3e7
canada4663 canada4663 x 26945fe
canada4663 canada4663 x 482d5c3
canada4663 canada4663 x 5bd6dd9
canada4663 canada4663 x 432a9e6
canada4663 canada4663 x 7d7025d
canada4663 canada4663 x 39c014e
canada4663 canada4663 Baseline 2 - Working with Real Tag Names 575b4b4
canada4663 canada4663 b ba45dcc
canada4663 canada4663 b 5d882d4
canada4663 canada4663 v.0.1 Release 7e97878
canada4663 canada4663 keystats Scraper - v0.1 Release
Release Works - Scraps Key Stats for Symbol and releases XML Tag Names
based on Paremeter & Value

to Test Before Pull: use
"http://raw.github.com/canada4663/yql-tables/master/yahoo/finance/yahoo.
finance.keystats.xml" as keystats; select * from keystats where
symbol="T";
ba15066
canada4663 canada4663 Clean Up Extraneous Files 62fcf6b
canada4663 canada4663 Starting Income Statement Development c08ab32
canada4663 canada4663 c 6780f43
canada4663 canada4663 Preliminary f603130
canada4663 canada4663 x 3e4a7d0
canada4663 canada4663 x dcd7aee
canada4663 canada4663 x b58dc1a
canada4663 canada4663 x aaeb320
canada4663 canada4663 x 456c7ae
canada4663 canada4663 x dd0db56
canada4663 canada4663 x 3afc5f4
canada4663 canada4663 x dbeb5cb
canada4663 canada4663 x 71e5c4c
canada4663 canada4663 x 03eff13
canada4663 canada4663 x 4dcd7af
canada4663 canada4663 x c0206fa
canada4663 canada4663 x 521b08f
canada4663 canada4663 x cdb92d0
canada4663 canada4663 x eb866f6
canada4663 canada4663 x e1e57e7
canada4663 canada4663 x 580c3bd
canada4663 canada4663 z 174a7f0
canada4663 canada4663 x 36bdfdd
canada4663 canada4663 x d13216d
canada4663 canada4663 x 7a20c26
canada4663 canada4663 x d4c9ad2
canada4663 canada4663 x b24be80
canada4663 canada4663 x 19a9ff7
canada4663 canada4663 x 2925b10
canada4663 canada4663 x deeead7
canada4663 canada4663 x 2d6633e
canada4663 canada4663 x 2469178
canada4663 canada4663 x 104d9d1
canada4663 canada4663 x 1c487ac
canada4663 canada4663 x 564ea09
canada4663 canada4663 x 4f07aed
canada4663 canada4663 x 156c4ce
canada4663 canada4663 x fe815f8
canada4663 canada4663 x 13f325f
canada4663 canada4663 x ac72f70
canada4663 canada4663 x b4b8cf4
canada4663 canada4663 x 73cda9e
canada4663 canada4663 x 95530e5
canada4663 canada4663 x 6dc2088
canada4663 canada4663 x 4dacd55
canada4663 canada4663 x b07733e
canada4663 canada4663 x 251f31f
canada4663 canada4663 x 236ece1
canada4663 canada4663 x fb70be3
canada4663 canada4663 x e867f73
canada4663 canada4663 x eab4ac2
canada4663 canada4663 x 90401b2
canada4663 canada4663 x a642bfb
canada4663 canada4663 x 92945d8
canada4663 canada4663 x c72e15f
canada4663 canada4663 x cbc2bce
canada4663 canada4663 x 6fd92e0
canada4663 canada4663 x 6b48d89
canada4663 canada4663 x 791db40
canada4663 canada4663 x 20dde8e
canada4663 canada4663 x 80ed37b
canada4663 canada4663 x 81371ec
canada4663 canada4663 x b2b05dd
canada4663 canada4663 x 420b572
canada4663 canada4663 x ae68156
canada4663 canada4663 x 770db50
canada4663 canada4663 x 3e4789f
canada4663 canada4663 x 2802eb1
canada4663 canada4663 x aaab1cb
canada4663 canada4663 x 2828f1e
canada4663 canada4663 x e4cf422
canada4663 canada4663 x 42c5c42
canada4663 canada4663 x daa1761
canada4663 canada4663 x a6dcd55
canada4663 canada4663 x a53fa4a
canada4663 canada4663 x b294882
canada4663 canada4663 x dbd4d92
canada4663 canada4663 x a9841aa
canada4663 canada4663 x cc004ce
canada4663 canada4663 x 5c27c6f
canada4663 canada4663 x 5419f4e
canada4663 canada4663 x 0845564
canada4663 canada4663 Release Candidate dcee243
canada4663 canada4663 x 7bef19d
canada4663 canada4663 x 27d0d8f
canada4663 canada4663 x 85060a7
canada4663 canada4663 x 59f2273
canada4663 canada4663 Income Statement - v0.1 - Working c8ddf6e
canada4663 canada4663 Start Debugging Diff vs. Income Statement 0c153ee
canada4663 canada4663 x 1fbfc42
canada4663 canada4663 x e8a77e3
canada4663 canada4663 x 4d7a5bc
canada4663 canada4663 x bedde5a
canada4663 canada4663 Balance Sheet - Working - v0.1 760a9c7
canada4663 canada4663 Cash Flow - Working - v0.1 2fbe9e1
canada4663 canada4663 Clean Up Development Files 15dc05d
canada4663 canada4663 Financial Statements YQL Tables - v0.1 b2032ed
canada4663 canada4663 Cleaning Up f84641e
canada4663 canada4663 Cleaning Up fa88e05
Paul Donnelly pjdonnelly merged commit aca29a8 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
3  .gitignore
View
@@ -0,0 +1,3 @@
+*.swp
+.DS_Store
+*info
BIN  yahoo/finance/.DS_Store
View
Binary file not shown
148 yahoo/finance/yahoo.finance.balancesheet.xml
View
@@ -0,0 +1,148 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<table xmlns="http://query.yahooapis.com/v1/schema/table.xsd">
+ <meta>
+ <author>
+ Ryan Hoium
+ </author>
+ <description>
+ Yahoo Finance - Balance Sheet v0.1
+ </description>
+ <sampleQuery>
+ SELECT * FROM {table} WHERE symbol='T'
+ </sampleQuery>
+ </meta>
+ <bindings>
+ <select itemPath="" produces="XML">
+ <urls>
+ <url>
+ </url>
+ </urls>
+ <inputs>
+ <key id="symbol" type="xs:string" paramType="variable" required="true" />
+ <key id="reporttype" type="xs:string" paramType="variable" default="" required="false" />
+ <key id="timeframe" type="xs:string" paramType="variable" default="quarterly" required="false" />
+ </inputs>
+ <execute>
+ <![CDATA[
+ //UTILITY: pad string with leading char
+ String.prototype.pad = function ( padchar, padlen )
+ {
+ s = this
+
+ while (s.length < padlen)
+ {
+ s = padchar + s;
+ }
+
+ return s;
+ }
+
+ //UTILITY: convert string to INTEGER
+ String.prototype.toInt = function ()
+ {
+ // remove leading 0's because otherwise
+ // str can be interpreted as Octal
+ var str = this.replace( /^0+/, '' );
+
+ // also the thousands comma was cousing trouble
+ str = str.trim()
+ str = str.replace( /\,/g, '' );
+
+ // replace M with 6 ZEROs, B with 9 ZEROs (UPDATE THIS - ACCOUNT FOR DECIMAL!!
+ //str = str.replace(/M/g,'000000');
+ //str = str.replace(/B/g,'000000000');
+
+ return parseInt( str );
+ }
+ //UTILITY: trim whitespace
+ String.prototype.trim = function ()
+ {
+ var str = this.replace( /^\s\s*/, "" ),
+ ws = /\s/,
+ i = str.length;
+ while ( ws.test( str.charAt( --i ) ) );
+ return str.slice( 0, i + 1 );
+ }
+
+ // Setup Query from finance.yahoo.com
+ var reporttype_code = "";
+ reporttype = y.context.table;
+ if(reporttype == "incomestatement"){reporttype_code = "is";}
+ else if(reporttype == "balancesheet"){reporttype_code = "bs";}
+ else if(reporttype == "cashflow"){reporttype_code = "cf";}
+ var url="http://finance.yahoo.com/q/"+ reporttype_code + "?s=" + symbol + "&" + timeframe;
+ var restquery = y.rest( url );
+ var rawresult = restquery.accept( "text/html" ).get().response;
+ var query = y.xpath( rawresult, "//table[@class='yfnc_tabledata1']/tr/td/table/tr");
+
+ // Process Results
+ var outputdata = <{reporttype} symbol={symbol} timeframe={timeframe}></{reporttype}>;
+ if ( query.*.length() !== 0 )
+ {
+ var y = 0; var x = 0;
+ var numcolumns = 0;
+ var data_array = new Array();
+
+ // Read Column Headings
+ data_array[0] = new Array()
+ data_array[0][0] = "Headings"
+ for each ( var th in query[0].td)
+ {
+ data_array[x] = new Array();
+ data_array[x][y] = th.*.text().toString();
+ //outputdata.appendChild(<column x={x} y={y}>{data_array[x][y]}</column>);
+ x++;
+ }
+ numcolumns = x;
+
+ // Read Rows
+ y = 1;
+ var i = 1;
+ while ( i < query.length())
+ {
+ var row = query[i];
+ if(row.td.length() >= numcolumns){
+ x = 0;
+ // read each column in row
+ for each (var column in row.td){
+ if("spacer" in column)
+ {}
+ else{
+ var dataitem = column.*.text().toString();
+ dataitem = String(dataitem.replace(/\s+/g,""));
+ dataitem = String(dataitem.replace(/,/g,""));
+ dataitem = String(dataitem.replace(/\//g,"_"));
+ if(dataitem.match(/^[\(\)]/)){
+ dataitem = Number(dataitem.replace(/[\(\)]/g,"")) * -1000;
+ } else if(dataitem.match(/^[0-9]{1,}$/)){
+ dataitem = Number(dataitem) * 1000;
+ }
+ data_array[x][y] = dataitem;
+ //outputdata.appendChild(<row x={x} y={y}>{dataitem}</row>);
+ x++;
+ }
+ }
+ y++;
+ }
+ i++;
+ }
+ var numrows = y;
+ x = 0; y = 0;
+ for(x = 1; x < numcolumns; x++){
+ var period = data_array[x][0];
+ var financial_period = <statement period={period}></statement>;
+ for(y = 1; y < numrows; y++){
+ row_name = data_array[0][y];
+ data = data_array[x][y];
+ financial_period.appendChild(<{row_name} report_row={y}>{data}</{row_name}>);
+ }
+ outputdata.appendChild(financial_period);
+ }
+ }
+ // Return statsdata strucuture
+ response.object = outputdata;
+ ]]>
+ </execute>
+ </select>
+ </bindings>
+</table>
152 yahoo/finance/yahoo.finance.cashflow.xml
View
@@ -0,0 +1,152 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<table xmlns="http://query.yahooapis.com/v1/schema/table.xsd">
+ <meta>
+ <author>
+ Ryan Hoium
+ </author>
+ <description>
+ Yahoo Finance - Cash Flow v0.1
+ </description>
+ <sampleQuery>
+ SELECT * FROM {table} WHERE symbol='T'
+ </sampleQuery>
+ </meta>
+ <bindings>
+ <select itemPath="" produces="XML">
+ <urls>
+ <url>
+ </url>
+ </urls>
+ <inputs>
+ <key id="symbol" type="xs:string" paramType="variable" required="true" />
+ <key id="reporttype" type="xs:string" paramType="variable" default="" required="false" />
+ <key id="timeframe" type="xs:string" paramType="variable" default="quarterly" required="false" />
+ </inputs>
+ <execute>
+ <![CDATA[
+ //UTILITY: pad string with leading char
+ String.prototype.pad = function ( padchar, padlen )
+ {
+ s = this
+
+ while (s.length < padlen)
+ {
+ s = padchar + s;
+ }
+
+ return s;
+ }
+
+ //UTILITY: convert string to INTEGER
+ String.prototype.toInt = function ()
+ {
+ // remove leading 0's because otherwise
+ // str can be interpreted as Octal
+ var str = this.replace( /^0+/, '' );
+
+ // also the thousands comma was cousing trouble
+ str = str.trim()
+ str = str.replace( /\,/g, '' );
+
+ // replace M with 6 ZEROs, B with 9 ZEROs (UPDATE THIS - ACCOUNT FOR DECIMAL!!
+ //str = str.replace(/M/g,'000000');
+ //str = str.replace(/B/g,'000000000');
+
+ return parseInt( str );
+ }
+ //UTILITY: trim whitespace
+ String.prototype.trim = function ()
+ {
+ var str = this.replace( /^\s\s*/, "" ),
+ ws = /\s/,
+ i = str.length;
+ while ( ws.test( str.charAt( --i ) ) );
+ return str.slice( 0, i + 1 );
+ }
+
+ // Setup Query from finance.yahoo.com
+ var reporttype_code = "";
+ reporttype = y.context.table;
+ if(reporttype == "incomestatement"){reporttype_code = "is";}
+ else if(reporttype == "balancesheet"){reporttype_code = "bs";}
+ else if(reporttype == "cashflow"){reporttype_code = "cf";}
+ var url="http://finance.yahoo.com/q/"+ reporttype_code + "?s=" + symbol + "&" + timeframe;
+ var restquery = y.rest( url );
+ var rawresult = restquery.accept( "text/html" ).get().response;
+ var query = y.xpath( rawresult, "//table[@class='yfnc_tabledata1']/tr/td/table/tr");
+
+ // Process Results
+ var outputdata = <{reporttype} symbol={symbol} timeframe={timeframe}></{reporttype}>;
+ if ( query.*.length() !== 0 )
+ {
+ //TODO: if re-write the reading of the columns slightly, same file can be shared
+ //TODO: for all 3 financial statements. income statement is a td element, followed by 3 th elements
+ //TODO: cash / balance sheet are simply 4 td elements - this is only difference between tables!
+
+ var y = 0; var x = 0;
+ var numcolumns = 0;
+ var data_array = new Array();
+
+ // Read Column Headings
+ data_array[0] = new Array()
+ data_array[0][0] = "Headings"
+ for each ( var th in query[0].td)
+ {
+ data_array[x] = new Array();
+ data_array[x][y] = th.*.text().toString();
+ //outputdata.appendChild(<column x={x} y={y}>{data_array[x][y]}</column>);
+ x++;
+ }
+ numcolumns = x;
+
+ // Read Rows
+ y = 1;
+ var i = 1;
+ while ( i < query.length())
+ {
+ var row = query[i];
+ if(row.td.length() >= numcolumns){
+ x = 0;
+ // read each column in row
+ for each (var column in row.td){
+ if("spacer" in column)
+ {}
+ else{
+ var dataitem = column.*.text().toString();
+ dataitem = String(dataitem.replace(/\s+/g,""));
+ dataitem = String(dataitem.replace(/,/g,""));
+ dataitem = String(dataitem.replace(/\//g,"_"));
+ if(dataitem.match(/^[\(\)]/)){
+ dataitem = Number(dataitem.replace(/[\(\)]/g,"")) * -1000;
+ } else if(dataitem.match(/^[0-9]{1,}$/)){
+ dataitem = Number(dataitem) * 1000;
+ }
+ data_array[x][y] = dataitem;
+ //outputdata.appendChild(<row x={x} y={y}>{dataitem}</row>);
+ x++;
+ }
+ }
+ y++;
+ }
+ i++;
+ }
+ var numrows = y;
+ x = 0; y = 0;
+ for(x = 1; x < numcolumns; x++){
+ var period = data_array[x][0];
+ var financial_period = <statement period={period}></statement>;
+ for(y = 1; y < numrows; y++){
+ row_name = data_array[0][y];
+ data = data_array[x][y];
+ financial_period.appendChild(<{row_name} report_row={y}>{data}</{row_name}>);
+ }
+ outputdata.appendChild(financial_period);
+ }
+ }
+ // Return statsdata strucuture
+ response.object = outputdata;
+ ]]>
+ </execute>
+ </select>
+ </bindings>
+</table>
87 yahoo/finance/yahoo.finance.com-info
View
@@ -0,0 +1,87 @@
+Financial Statements
+http://finance.yahoo.com/q/{statement_type}?s={SYMBOL}&{annual|quarterly}
+ statement_type = is = income statements, bs = balance sheet, cf = cash flow
+
+Analyst
+http://finance.yahoo.com/q/ae?s=VZ+Analyst+Estimates
+ ae = analyst estimate
+ ao = analyst opionon
+
+
+YQL Java Code to Parse finance.yahoo.com tables (example from options chain):
+
+ var yQuery = y.rest( optionsChainURL );
+ var data = yQuery.accept( "text/html" ).get().response;
+
+ var optionsChainQuery = y.xpath(
+ data,
+ "//table[@class='yfnc_datamodoutline1']/tr/td/table/tr[td[@class='yfnc_h' or " +
+ "@class='yfnc_tabledata1']]"
+ );
+
+ var expiresQuery = y.xpath(
+ data,
+ "//table[@class='yfnc_mod_table_title1']/tr/td[last()]/p"
+ );
+
+
+** xpath( method is used to pull just the rows requested
+ find the @class parameter inside using safari view source mode
+
+Income Statement:
+
+var incomestatementURL = "http://finance.yahoo.com/q/is?s=" + symbol + "&annual";
+var yQuery = y.rest (incomestatementURL);
+var data = yQuery.accept("text/html").get().response;
+var financials_query = y.xpath(
+ data,
+ "//tr[@class='yfnc_modtitle1'/th/tr/td/p")
+
+github live for yql:
+
+raw for development with console:
+select * from html where url="http://finance.yahoo.com/q/is?s=T" and xpath='//table[@class="yfnc_tabledata1"]/tr/td/table/tr'
+
+Key Statistics (COMPLETE)
+
+github live for yql:
+use "http://raw.github.com/canada4663/yql-tables/master/yahoo/finance/yahoo.finance.keystats.xml" as keystats; select * from keystats where symbol="T";
+
+raw for development:
+select * from html where url="http://finance.yahoo.com/q/ks?s=TXN" and xpath='//table[@class="yfnc_datamodoutline1"]/tr/td/table/tr/td[@class="yfnc_tabledata1" or @class="yfnc_tablehead1"]'
+ Outputs:
+
+ <results>
+ <td class="yfnc_tablehead1" width="74%">
+ <p>Market Cap (intraday)
+ <font size="-1">
+ <sup>5</sup>
+ </font>:</p>
+ </td>
+ <td class="yfnc_tabledata1">
+ <span id="yfs_j10_txn">34.67B</span>
+ </td>
+ <td class="yfnc_tablehead1" width="74%">
+ <p>Enterprise Value (Dec 26, 2012)
+ <font size="-1">
+ <sup>3</sup>
+ </font>:</p>
+ </td>
+ <td class="yfnc_tabledata1">
+ <p>36.70B</p>
+ </td>
+ <td class="yfnc_tablehead1" width="74%">
+ <p>Trailing P/E (ttm, intraday):</p>
+ </td>
+ <td class="yfnc_tabledata1">
+ <p>20.30</p>
+ </td>
+ <td class="yfnc_tablehead1" width="74%">
+ <p>Forward P/E (fye Dec 31, 2013)
+ <font size="-1">
+ <sup>1</sup>
+ </font>:</p>
+ </td>
+ **** END EXAMPLE ****
+
+ 0
148 yahoo/finance/yahoo.finance.incomestatement.xml
View
@@ -0,0 +1,148 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<table xmlns="http://query.yahooapis.com/v1/schema/table.xsd">
+ <meta>
+ <author>
+ Ryan Hoium
+ </author>
+ <description>
+ Yahoo Finance - Income Statement v0.1
+ </description>
+ <sampleQuery>
+ SELECT * FROM {table} WHERE symbol='T'
+ </sampleQuery>
+ </meta>
+ <bindings>
+ <select itemPath="" produces="XML">
+ <urls>
+ <url>
+ </url>
+ </urls>
+ <inputs>
+ <key id="symbol" type="xs:string" paramType="variable" required="true" />
+ <key id="reporttype" type="xs:string" paramType="variable" default="" required="false" />
+ <key id="timeframe" type="xs:string" paramType="variable" default="quarterly" required="false" />
+ </inputs>
+ <execute>
+ <![CDATA[
+ //UTILITY: pad string with leading char
+ String.prototype.pad = function ( padchar, padlen )
+ {
+ s = this
+
+ while (s.length < padlen)
+ {
+ s = padchar + s;
+ }
+
+ return s;
+ }
+
+ //UTILITY: convert string to INTEGER
+ String.prototype.toInt = function ()
+ {
+ // remove leading 0's because otherwise
+ // str can be interpreted as Octal
+ var str = this.replace( /^0+/, '' );
+
+ // also the thousands comma was cousing trouble
+ str = str.trim()
+ str = str.replace( /\,/g, '' );
+
+ // replace M with 6 ZEROs, B with 9 ZEROs (UPDATE THIS - ACCOUNT FOR DECIMAL!!
+ //str = str.replace(/M/g,'000000');
+ //str = str.replace(/B/g,'000000000');
+
+ return parseInt( str );
+ }
+ //UTILITY: trim whitespace
+ String.prototype.trim = function ()
+ {
+ var str = this.replace( /^\s\s*/, "" ),
+ ws = /\s/,
+ i = str.length;
+ while ( ws.test( str.charAt( --i ) ) );
+ return str.slice( 0, i + 1 );
+ }
+
+ // Setup Query from finance.yahoo.com
+ var reporttype_code = "";
+ reporttype = y.context.table;
+ if(reporttype == "incomestatement"){reporttype_code = "is";}
+ else if(reporttype == "balancesheet"){reporttype_code = "bs";}
+ else if(reporttype == "cashflow"){reporttype_code = "cf";}
+ var url="http://finance.yahoo.com/q/"+ reporttype_code + "?s=" + symbol + "&" + timeframe;
+ var restquery = y.rest( url );
+ var rawresult = restquery.accept( "text/html" ).get().response;
+ var query = y.xpath( rawresult, "//table[@class='yfnc_tabledata1']/tr/td/table/tr");
+
+ // Process Results
+ var outputdata = <{reporttype} symbol={symbol} timeframe={timeframe}></{reporttype}>;
+ if ( query.*.length() !== 0 )
+ {
+ var y = 0; var x = 1;
+ var numcolumns = 0;
+ var data_array = new Array();
+
+ // Read Column Headings
+ data_array[0] = new Array()
+ data_array[0][0] = "Headings"
+ for each ( var th in query[0].th)
+ {
+ data_array[x] = new Array();
+ data_array[x][y] = th.*.text().toString();
+ //outputdata.appendChild(<column x={x} y={y}>{data_array[x][y]}</column>);
+ x++;
+ }
+ numcolumns = x;
+
+ // Read Rows
+ y = 1;
+ var i = 1;
+ while ( i < query.length())
+ {
+ var row = query[i];
+ if(row.td.length() >= numcolumns){
+ x = 0;
+ // read each column in row
+ for each (var column in row.td){
+ if("spacer" in column)
+ {}
+ else{
+ var dataitem = column.*.text().toString();
+ dataitem = String(dataitem.replace(/\s+/g,""));
+ dataitem = String(dataitem.replace(/,/g,""));
+ dataitem = String(dataitem.replace(/\//g,"_"));
+ if(dataitem.match(/^[\(\)]/)){
+ dataitem = Number(dataitem.replace(/[\(\)]/g,"")) * -1000;
+ } else if(dataitem.match(/^[0-9]{1,}$/)){
+ dataitem = Number(dataitem) * 1000;
+ }
+ data_array[x][y] = dataitem;
+ //outputdata.appendChild(<row x={x} y={y}>{data_array[x][y]}</row>);
+ x++;
+ }
+ }
+ y++;
+ }
+ i++;
+ }
+ var numrows = y;
+ x = 0; y = 0;
+ for(x = 1; x < numcolumns; x++){
+ var period = data_array[x][0];
+ var financial_period = <statement period={period}></statement>;
+ for(y = 1; y < numrows; y++){
+ row_name = data_array[0][y];
+ data = data_array[x][y];
+ financial_period.appendChild(<{row_name} report_row={y}>{data}</{row_name}>);
+ }
+ outputdata.appendChild(financial_period);
+ }
+ }
+ // Return statsdata strucuture
+ response.object = outputdata;
+ ]]>
+ </execute>
+ </select>
+ </bindings>
+</table>
136 yahoo/finance/yahoo.finance.keystats.xml
View
@@ -0,0 +1,136 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<table xmlns="http://query.yahooapis.com/v1/schema/table.xsd">
+ <meta>
+ <author>
+ Ryan Hoium
+ </author>
+ <description>
+ Yahoo Finance - Key Statistics by Stock Symbol
+ </description>
+ <sampleQuery>
+ SELECT * FROM {table} WHERE symbol='T'
+ </sampleQuery>
+ </meta>
+ <bindings>
+ <select itemPath="" produces="XML">
+ <urls>
+ <url>
+ </url>
+ </urls>
+ <inputs>
+ <key id="symbol" type="xs:string" paramType="variable" required="true" />
+ </inputs>
+ <execute>
+ <![CDATA[
+ //UTILITY: pad string with leading char
+ String.prototype.pad = function ( padchar, padlen )
+ {
+ s = this
+
+ while (s.length < padlen)
+ {
+ s = padchar + s;
+ }
+
+ return s;
+ }
+
+ //UTILITY: convert string to INTEGER
+ String.prototype.toInt = function ()
+ {
+ // remove leading 0's because otherwise
+ // str can be interpreted as Octal
+ var str = this.replace( /^0+/, '' );
+
+ // also the thousands comma was cousing trouble
+ str = str.trim()
+ str = str.replace( /\,/g, '' );
+
+ // replace M with 6 ZEROs, B with 9 ZEROs (UPDATE THIS - ACCOUNT FOR DECIMAL!!
+ //str = str.replace(/M/g,'000000');
+ //str = str.replace(/B/g,'000000000');
+
+ return parseInt( str );
+ }
+ //UTILITY: trim whitespace
+ String.prototype.trim = function ()
+ {
+ var str = this.replace( /^\s\s*/, "" ),
+ ws = /\s/,
+ i = str.length;
+ while ( ws.test( str.charAt( --i ) ) );
+ return str.slice( 0, i + 1 );
+ }
+
+ // Setup Query from finance.yahoo.com
+ var url="http://finance.yahoo.com/q/ks?s=" + symbol;
+ var restquery = y.rest( url );
+ var rawresult = restquery.accept( "text/html" ).get().response;
+ var keystatsquery = y.xpath(
+ rawresult,
+ "//table[@class='yfnc_datamodoutline1']/tr/td/table/tr" +
+ "/td[@class='yfnc_tabledata1' or @class='yfnc_tablehead1']"
+ );
+
+
+ // Process Results
+ var statsdata = <stats symbol={symbol}></stats>;
+ if ( keystatsquery.*.length() != 0 )
+ {
+
+ var i = 0;
+ while ( i < keystatsquery.length())
+ {
+ // Setup to Process Two 'td' Elements at a Time - Name and Value Pairs
+ var td_param_name = keystatsquery[i];
+ var td_value = keystatsquery[i+1];
+ var param_name = "";
+ var attr = "";
+ var value = "";
+ i = i + 2;
+
+ // Process Parameter Name and any Associated Attributes (Timeframe, Stock Split Info)
+ param_name = td_param_name.p.text().toString();
+ param_name = String(param_name.replace(/:/g,""));
+ attr = String(param_name.match(/\(.*\)/));
+ attr = String(attr.trim());
+ attr = attr.replace(/[\(\)]/g,"");
+ param_name = String(param_name.replace(/\(.*\)/g,""));
+ param_name = String(param_name.replace(/\s/g,""));
+ param_name = String(param_name.replace(/\&/g,""));
+ param_name = String(param_name.replace(/\//g,""));
+ param_name = String(param_name.replace(/\%/g,"Percentage"));
+ param_name = String(param_name.replace(/-/g,"_"));
+ if(param_name.match(/^\d/)){ param_name = String("p_" + param_name);}
+ param_name = param_name.trim();
+
+ // Process Value Information
+ value = td_value.p.text().toString();
+ // Catch When it is Span Tag instead of P tag
+ if( value == false){
+ value = td_value.span.text().toString();
+ }
+ //Replace B, M, K with Proper Trailing Zeroes/Decimal Handling
+ if(value.match(/[Bb]$/)){ value = value.replace(/[Bb]$/,""); value = value * 1000000000;}
+ else if(value.match(/[Mm]$/)){ value = value.replace(/[Mm]$/,""); value = value * 1000000;}
+ else if(value.match(/[Kk]$/)){ value = value.replace(/[Kk]$/,""); value = value * 1000;}
+
+ // Append Value Pair to XML Structure
+ if(attr !== "null"){ statsdata.appendChild(<{param_name} term={attr}> {value} </{param_name}>);}
+ else { statsdata.appendChild(<{param_name}> {value} </{param_name}>);}
+
+ }
+ }
+ // Return statsdata strucuture
+ response.object = statsdata;
+
+
+
+
+
+
+ ]]>
+ </execute>
+ </select>
+ </bindings>
+</table>
Something went wrong with that request. Please try again.