From d29175bf93ead4db65cfd37fa550404ea2decced Mon Sep 17 00:00:00 2001 From: abalogh Date: Wed, 27 May 2015 10:06:05 +0300 Subject: [PATCH] Update yahoo.finance.analystestimate.xml Changed all xpaths to have tbody also, it does not work without tbody. --- .../finance/yahoo.finance.analystestimate.xml | 81 +++++++++++-------- 1 file changed, 46 insertions(+), 35 deletions(-) diff --git a/yahoo/finance/yahoo.finance.analystestimate.xml b/yahoo/finance/yahoo.finance.analystestimate.xml index 2d94efef..28233630 100644 --- a/yahoo/finance/yahoo.finance.analystestimate.xml +++ b/yahoo/finance/yahoo.finance.analystestimate.xml @@ -23,7 +23,8 @@ function getelement(row) { if(row.hasOwnProperty("p")) return(row.p.text()); - return(row.font.text()); + else if(row.hasOwnProperty("font")) return(row.font.text()); + return row.text(); } // Setup Query from finance.yahoo.com @@ -32,8 +33,8 @@ var rawresult = restquery.accept( "text/html" ).get().response; var aequery = y.xpath( rawresult, - "//table[@class='yfnc_tableout1']/tr[count(td)=0]/parent::*|" + - "//table[@class='yfnc_tableout1']/tr/td/table" + "//table[@class='yfnc_tableout1']/tbody/tr[count(td)=0]/parent::*/parent::*|"+ + "//table[@class='yfnc_tableout1']/tbody/tr/td/table" ); // Process Results @@ -42,38 +43,49 @@ while(i < aequery.length()) { var table = aequery[i]; - var thead = table.tr[0]; - var tname = thead.th[0].strong.text().toString().replace(/ /g, ""); - var fname1 = thead.th[1].p.text().toString().replace(/\n.*/, ""); - var fname2 = thead.th[2].p.text().toString().replace(/\n.*/, ""); - var fname3 = thead.th[3].p.text().toString().replace(/\n.*/, ""); - var fname4 = thead.th[4].p.text().toString().replace(/\n.*/, ""); - fname1 = fname1.replace(/[\s\.]+/g, "").replace(/\&/,""); - fname2 = fname2.replace(/[\s\.]+/g, "").replace(/\&/,""); - fname3 = fname3.replace(/[\s\.]+/g, "").replace(/\&/,""); - fname4 = fname4.replace(/[\s\.]+/g, "").replace(/\&/,""); - - var tblval = <{tname}>; - var j = 1; - while(j < table.tr.length()) + var thead = table.tbody.tr[0]; + if(thead) { - var row = table.tr[j].td; - var rname = row[0].p.text().toString().replace(/[\s\.]+/g, ""); - rname = rname.replace(/\(.*\)/g,"").replace(/\%/,"").replace(/^(\d)/,"_$1"); - rname = rname.replace(/\//, ""); - var rval1 = getelement(row[1]); - var rval2 = getelement(row[2]); - var rval3 = getelement(row[3]); - var rval4 = getelement(row[4]); - tblval.appendChild(<{rname}> - <{fname1}>{rval1} - <{fname2}>{rval2} - <{fname3}>{rval3} - <{fname4}>{rval4} - ); - j = j + 1; - } - aedata.appendChild(tblval); + var tname = thead.th[0].strong.text().toString().replace(/ /g, ""); + var fname1 = thead.th[1].text().toString().replace(/\n.*/, ""); + var fname2 = thead.th[2].text().toString().replace(/\n.*/, ""); + var fname3 = thead.th[3].text().toString().replace(/\n.*/, ""); + var fname4 = thead.th[4].text().toString().replace(/\n.*/, ""); + fname1 = fname1.replace(/[\s\.]+/g, "").replace(/\&/,""); + fname2 = fname2.replace(/[\s\.]+/g, "").replace(/\&/,""); + fname3 = fname3.replace(/[\s\.]+/g, "").replace(/\&/,""); + fname4 = fname4.replace(/[\s\.]+/g, "").replace(/\&/,""); + + var tblval = <{tname}>; + var j = 1; + while(j < table.tbody.tr.length()) + { + var tr = table.tbody.tr[j]; + if(tr) + { + var row=tr.td; + if(row) + { + var rname = row[0].text().toString().replace(/[\s\.]+/g, ""); + rname = rname.replace(/\(.*\)/g,"").replace(/\%/,"").replace(/^(\d)/,"_$1"); + rname = rname.replace(/\//, ""); + var rval1 = getelement(row[1]); + var rval2 = getelement(row[2]); + var rval3 = getelement(row[3]); + var rval4 = getelement(row[4]); + tblval.appendChild(<{rname}> + <{fname1}>{rval1} + <{fname2}>{rval2} + <{fname3}>{rval3} + <{fname4}>{rval4} + ); + } + } + j = j + 1; + } + + aedata.appendChild(tblval); + } i = i + 1; } @@ -84,4 +96,3 @@ -