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