Are the yahoo.finance related data api's change (YQL Console)?

泄露秘密 提交于 2019-12-10 13:11:59

问题


I am trying to use yql for yahoo financial data. I checked the Show Community Table on the YQL console to see the database under the Yahoo tag. I can see the tables under it but i am not getting results here it is as follows:::

select * from yahoo.finance.analystestimate where symbol in ('YHOO')

    {
 "query": {
  "count": 1,
  "created": "2016-03-28T10:25:01Z",
  "lang": "en-US",
  "diagnostics": {
   "url": [
    {
     "execution-start-time": "1",
     "execution-stop-time": "767",
     "execution-time": "766",
     "content": "http://www.datatables.org/yahoo/finance/yahoo.finance.analystestimate.xml"
    },
    {
     "execution-start-time": "771",
     "execution-stop-time": "1821",
     "execution-time": "1050",
     "content": "http://finance.yahoo.com/q/ae?s=YHOO"
    }
   ],
   "publiclyCallable": "true",
   "javascript": {
    "execution-start-time": "769",
    "execution-stop-time": "1823",
    "execution-time": "1054",
    "instructions-used": "5139",
    "table-name": "yahoo.finance.analystestimate"
   },
   "user-time": "1824",
   "service-time": "1806",
   "build-version": "0.2.842"
  },
  "results": {
   "results": {
    "symbol": "YHOO"
   }
  }
 }
}

here results are shown as empty .. Has something changed? How can I find out what happened?

Is there an alternative solution I can use to obtain this data?


回答1:


The JS the developer used to create the table us no longer working. This is it partially formatted. You can see that he's grabbing the page and then screen scraping it.

function getelement(row) {
    if (row.hasOwnProperty("p")) return (row.p.text());
    return (row.font.text());
} // Setup Query from finance.yahoo.com 
var url = "http://finance.yahoo.com/q/ae?s=" + symbol;
var restquery = y.rest(url);
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");
// Process Results 
var aedata = < results symbol = {
        symbol
    } > < /results>; var i = 0; 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
    } > < /{tname}>; var j = 1; while(j < table.tr.length()) { 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
        } < /{fname1}> <{fname2}>{rval2}</ {
            fname2
        } > < {
            fname3
        } > {
            rval3
        } < /{fname3}> <{fname4}>{rval4}</ {
            fname4
        } > < /{rname}>); j = j + 1; } aedata.appendChild(tblval); i = i + 1; } 
        // Return aedata strucuture 
        response.object = aedata;



回答2:


Yes, the HTML structure for finance.yahoo.com has been changed somewhere in beginning of 2015, so YQL table implementation needs updating.

Please check the following GH pull requests which aims to fix the current outstanding issues:

  • GH-449: Update yahoo.finance.analystestimate.xml to new HTML structure
  • GH-457: Update yahoo.finance.analystestimate.xml

They're bit in overlap, so you may test them both (preferably check the first one).

Or you can check my fork of yql-tables (which consist loads of other fixes as well) where I've merged this PR into it, so find updated yahoo.finance.analystestimate.xml in here, the other one doesn't merge on top of the other one.



来源:https://stackoverflow.com/questions/36260484/are-the-yahoo-finance-related-data-apis-change-yql-console

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!