19
rated 0 times
[
20]
[
1]
/ answers: 1 / hits: 18493
/ 12 Years ago, sat, january 26, 2013, 12:00:00
I want to to get data within divs from other websites.
How can I do that using JavaScript?
More From » jquery
I want to to get data within divs from other websites.
How can I do that using JavaScript?
Due to cross domain restrictions you can't access the html directly using AJAX.
You can however use Yahoo YQL
to select the part(s) of a page you want and have that html returned within jsonp
data.
Example returning list of questions on main page of stackoverflow
var url='http://query.yahooapis.com/v1/public/yql?q=select * from html where url='http://stackoverflow.com/' and xpath='//div[@id="question-mini-list"]//h3//a'&format=json&callback=?';
$.getJSON( url, function(data){
$.each(data.query.results.a, function(){
$('body').append('<div><a href="http://stackoverflow.com'+this.href +'">'+this.content+'</a></div>')
})
})
DEMO: http://jsfiddle.net/NTUx5/
YQL docs: http://developer.yahoo.com/yql/guide/index.html
EDIT: This does not work any more.