¿Cómo puedo escribir esta declaración YQL para jsonp jQuery
Pregunta
Estoy tratando de hacer algunas cosas dominios con YQL y jQuery pero estoy teniendo un pequeño problema con la obtención de esta consulta yql a la derecha de trabajo.
Bueno por lo que esta es la declaración YQL que estoy tratando de llegar al trabajo:
use 'http://yqlblog.net/samples/data.html.cssselect.xml' as data.html.cssselect; select * from data.html.cssselect where url="www.holylandmoments.org/devotionals/the-sabbath-experience" and css="#main-content p"
Ahora la declaración yql que yo estoy tratando de cambiar al juego lo que estoy tratando de hacer es:
var yql = 'http://query.yahooapis.com/v1/public/yql?q=' + encodeURIComponent('select * from html where url="' + site + '"') + '&format=xml&callback=?';
Por lo que he leído con el fin de que sea capaz de escoger y elegir los selectores CSS necesito invocar una tabla de datos abierta.
No sé qué o cómo puedo cambiar la sentencia del ejemplo yql para incluir el uso y AS en la consulta.
Cualquier ayuda sería hacer.
Solución
yo bien se que ... si alguien necesita algo como esto a echar un vistazo:
// Accepts a url and a callback function to run.
función requestCrossDomain (sitio, de devolución de llamada) {
// Take the provided url, and add it to a YQL query. Make sure you encode it!
var yql = 'http://query.yahooapis.com/v1/public/yql?q=use' + "%20'http%3A%2F%2Fyqlblog.net%2Fsamples%2Fdata.html.cssselect.xml'%20as%20data.html.cssselect%3B%20" + encodeURIComponent('select * from data.html.cssselect where url="' + site + '"') + "%20and%20css%3D%22%23main-content%20p%22" + '&format=xml&callback=?';
// Request that YSQL string, and run a callback function.
// Pass a defined function to prevent cache-busting.
$.getJSON( yql, cbFunc );
function cbFunc(data) {
// If we have something to work with...
if ( data.results[0] ) {
// Strip out all script tags, for security reasons.
// BE VERY CAREFUL. This helps, but we should do more.
data = data.results[0].replace(/<script[^>]*>[\s\S]*?<\/script>/gi, '');
// If the user passed a callback, and it
// is a function, call it, and send through the data var.
if ( typeof callback === 'function') {
callback(data);
}
}
// Else, Maybe we requested a site that doesn't exist, and nothing returned.
else throw new Error('Nothing returned from getJSON.');
}
}
Otros consejos
véase el siguiente ejemplo de cómo obtener las noticias de YQL JSONP
http: / /www.techtricky.com/jquery-code-to-display-top-news-using-yql-jsonp-api-service/