【问题标题】:Get value with yql用yql获取价值
【发布时间】:2015-07-24 11:23:02
【问题描述】:

我在 yql 中执行此查询,它在 yahoo 控制台中运行良好,但我认为错误在脚本中,这是我写的。我只需要得到日期,我没有得到他。什么是错的。这是脚本。

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);
    });

【问题讨论】:

    标签: jquery ajax json yql


    【解决方案1】:

    需要编码yql参数使用encodeURIComponent()

    encodeURIComponent() 方法通过将某些字符的每个实例替换为表示字符的 UTF-8 编码的一个、两个、三个或四个转义序列(将只有四个转义由两个“代理”字符组成的字符序列

    使用

    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>

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-04-09
      • 2019-04-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多