Created
November 21, 2010 13:00
-
-
Save markandey/708723 to your computer and use it in GitHub Desktop.
Example code to get data from wikipedia page using YQL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<HTML> | |
<HEAD> | |
<TITLE>YQL DEMO</TITLE> | |
<script type="text/javascript"> | |
function renderYQL(o) { | |
var div = document.getElementById("main"); | |
var html = ""; | |
if (div) { | |
if (o.results[0]) { | |
count = o.results.length; | |
for (var i = 0; i < count; i++) { | |
html =html + o.results[i] + '<br/' + '>'; | |
} | |
div.innerHTML = html; | |
} else if (o.results) { | |
div.innerHTML = o.results; | |
} else { | |
div.innerHTML = 'failed'; | |
} | |
} | |
} | |
</script> | |
<style> | |
body{ | |
text-align:center; | |
} | |
#main{ | |
width:500px; | |
margin:auto; | |
} | |
</style> | |
</HEAD> | |
<BODY> | |
<strong>YQL Page Scraping Demo</strong> | |
<DIV id="main"> | |
Loading YQL JSON........... | |
</DIV> | |
<script src="http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20html%20where%20url%3D%22http%3A//en.wikipedia.org/wiki/Yahoo%21_query_language%22%20and%0A%20%20%20%20%20%20xpath%3D'//div%5B@id%3D%22bodyContent%22%5D/p%5B1%5D'&format=xml&diagnostics=true&callback=renderYQL"> | |
/* | |
Here we will get the JSON as | |
renderYQL({'results':'blah blah'}) | |
which will call the function renderYQL. | |
*/ | |
</script> | |
</BODY> | |
</HTML> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment