?Briella 2015-07-24 11:23 采纳率: 0%
浏览 25

通过yql获得价值

i do this query in yql' its run good in yahoo console, but i think the error is in the script, this what i wrote. i need to get only the Date, and i dont get him. whats is wrong. this is the script.

var yql = 'select * from html where url="http://finance.yahoo.com/q?s=mo&ql=1" AND xpath="//*[@id=\'table1\']//tr[7]//td/text()"';
    var queryURL = 'https://query.yahooapis.com/v1/public/yql?q=' + yql + '&format=json&env=http%3A%2F%2Fdatatables.org%2Falltables.env&callback=?';

    $.getJSON(queryURL, function (data) {
        var ss;
        $.each(data.query.results, function (index, item) {
            ss += item.results;
        });

        $("#test").html(ss);
    });
  • 写回答

1条回答 默认 最新

  • weixin_33725807 2015-07-24 11:26
    关注

    You need to encode yql parameter use encodeURIComponent()

    The encodeURIComponent() method encodes a Uniform Resource Identifier (URI) component by replacing each instance of certain characters by one, two, three, or four escape sequences representing the UTF-8 encoding of the character (will only be four escape sequences for characters composed of two "surrogate" characters

    Use

    var queryURL = 'https://query.yahooapis.com/v1/public/yql?q=' 
      + encodeURIComponent(yql)  //Notice here
      + '&format=json&env=http%3A%2F%2Fdatatables.org%2Falltables.env&callback=?';
    

    var yql = 'select * from html where url="http://finance.yahoo.com/q?s=mo&ql=1" AND xpath="//*[@id=\'table1\']//tr[7]//td/text()"';
    var queryURL = 'https://query.yahooapis.com/v1/public/yql?q=' + encodeURIComponent(yql) + '&format=json&env=http%3A%2F%2Fdatatables.org%2Falltables.env&callback=?';
    
    $.getJSON(queryURL, function(data) {
      alert(data.query.results);  
      console.log(data.query.results);
    });
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

    </div>
    
    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料