从Javascript响应对象提取YQL查询内容
我有一个javascript,使用Yql检索特定文本。我成功地检索到了文本,但我无法按我希望的方式处理它:我可以访问原始文本,而不必,正如您从调试器获取的对象中所看到的: 通过访问response.query.results.div.p.content,我可以访问原始文本,而s被排除在外,它们被无用地存储在br数组中。我怎样才能在正确的位置获得带有s的文本 这是我需要的代码 不确定你想用html做什么,所以我现在提醒你 不确定你想用html做什么,所以我现在提醒你从Javascript响应对象提取YQL查询内容,javascript,xpath,yql,Javascript,Xpath,Yql,我有一个javascript,使用Yql检索特定文本。我成功地检索到了文本,但我无法按我希望的方式处理它:我可以访问原始文本,而不必,正如您从调试器获取的对象中所看到的: 通过访问response.query.results.div.p.content,我可以访问原始文本,而s被排除在外,它们被无用地存储在br数组中。我怎样才能在正确的位置获得带有s的文本 这是我需要的代码 不确定你想用html做什么,所以我现在提醒你 不确定你想用html做什么,所以我现在提醒你 YUI().use('node
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 */ }
});
});
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 */ }
});
});