我在yql‘is run good in yahoo console中做了这个查询,但我认为错误在脚本中,这是我写的。我只需要得到日期,而我不能得到他。出了什么问题。这就是脚本。
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);
});发布于 2015-07-24 19:26:58
需要使用encodeURIComponent()对yql参数进行编码
encodeURIComponent()方法通过将某些字符的每个实例替换为一个、两个、三个或四个转义序列来编码统一资源标识符(URI)组件,这些转义序列表示字符的UTF8编码(对于由两个“代理”字符组成的字符,将只有四个转义序列
使用
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>
https://stackoverflow.com/questions/31609300
复制相似问题