Question

I have a javascript using Yql to retrieve a certain text. I success in retrieving the text, but I cannot handle it how I would like to: I can have access to the raw text (without <br/>), as you can seen in the obtained object from the debugger:

The object inside the debugger

by accessing response.query.results.div.p.content i have access to the raw text, while the <br/>s are excluded (they are uselessly stored inside a br array). How can i obtain the text with the <br/>s in the right places?

This is my code (it requires http://yui.yahooapis.com/3.8.0/build/yui/yui-min.js)

YUI().use('node', 'event', 'yql', function(Y) {

                    var news_url = 'http://lyrics.wikia.com/Arcade_Fire:Wake_Up';

                    var yql_query = "select * from html where url='" + news_url +"'";
                    yql_query += " and xpath=\"//div[@class='lyricbox']\"";


                    Y.YQL(yql_query, function(response) {
                      if(response.query.results){

                                    /* presentation logic accessing 
                                    to response.query.results.div.p.content */
                       } else{ /* error handling */     }             
   });
});
Était-ce utile?

La solution

 YUI().use('node', 'event', 'yql', function(Y) {

                var news_url = 'http://lyrics.wikia.com/Arcade_Fire:Wake_Up';

                var yql_query = "select * from html where url='" + news_url +"'";
                yql_query += " and xpath=\"//div[@class='lyricbox']\"";


                Y.YQL(yql_query, function(response) {
                  if(response.query.results){
                     alert(
                      response.query.results.div.p.content.split(' \n ').join('<br />')
                     );

                                /* presentation logic accessing 
                                to response.query.results.div.p.content */
                   } else{ /* error handling */     }             
                });
});

not sure what you want to do with the html, so i alert for now...

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top