Skip to content

Instantly share code, notes, and snippets.

@hemantajax
Created March 9, 2012 17:08
Show Gist options
  • Save hemantajax/2007575 to your computer and use it in GitHub Desktop.
Save hemantajax/2007575 to your computer and use it in GitHub Desktop.
YQL:yql simple use
<!doctype html>
<head>
<title>YQL Simple Use</title>
<meta charset="utf-8" />
<style>
#result{
width:800px;
margin: 20px auto;
background-color: #DDD;
}
ul{
margin: 0;
padding: 0;
}
li{
list-style:none;
padding: 5px 10px;
margin-top: 10px;
background-color: #ff0;
}
</style>
</head>
<body>
<div id="result">
<h1>New to the Store</h1>
</div>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script>
(function(){
var yql="http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20html%20where%20url%3D%22http%3A%2F%2Fstore.apple.com%2Fus%22%20and%0A%20%20%20%20%20%20xpath%3D'%2Fhtml%2Fbody%2Fdiv%5B2%5D%2Fdiv%5B4%5D%2Fdiv%5B2%5D%2Fdiv%2Fdiv%5B2%5D%2Fdiv%2Ful'&format=json&diagnostics=true";
$.ajax({
url:yql,
dataType:"jsonp",
success:function(data){
var ulstr=$("<ul></ul>",{
class:"output"
}),
res="",
newarr=[];
newarr=$.map(data.query.results.ul.li,function(obj,i){
return{
text:obj.a.content,
href:"http://store.apple.com"+obj.a.href
};
});
$.each(newarr, function (i,obj) {
res+='<li><a href="'+obj.href+'" target="_blank">'+obj.text+'</a></li>';
});
ulstr=ulstr.html(res);
$("#result").append(ulstr);
},
error:function(e,e1,ex) {
// body...
}
});
})();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment