Skip to content

Instantly share code, notes, and snippets.

@inter-coder
Last active August 29, 2015 14:21
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save inter-coder/ccffb9ab7c8a4d677ed6 to your computer and use it in GitHub Desktop.
Gather html content from a remote url with JavaScript
function xdomain(par){//crossdomain function
par.xpath=par.xpath==undefined?"*":par.xpath;
par.type=par.type==undefined?"xml":par.type;
var xmlhttp=new XMLHttpRequest();
par.url = 'http://query.yahooapis.com/v1/public/yql?q='+encodeURIComponent('select * from html WHERE url="'+par.url+'" AND xpath="'+par.xpath+'"')+'&format='+par.type+'&callback=cb';
xmlhttp.open("GET",par.url,false);
xmlhttp.onload=function(){
function cb(d){return d;}//callBack function for returning results from query
par.callBack(eval(xmlhttp.responseText));
};
xmlhttp.send();
};
/* example usage
xdomain({
url:"http://cropdanka.com/",// url of site
type:"xml",//return in xml or JSON format
xpath:"*",//filter objects
callBack:function(data){
console.log(data);// display object returned from request
}
});
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment