Skip to content

Instantly share code, notes, and snippets.

@k4200
Created April 3, 2013 05:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save k4200/5298670 to your computer and use it in GitHub Desktop.
Save k4200/5298670 to your computer and use it in GitHub Desktop.
Scrape a page by using YQL
<html>
<header>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="/javascripts/jquery-1.6.4.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var url = "http://example.com/";
var query = 'select * from html where url="' + url + '" and xpath="*"';
var apiUrl = "http://query.yahooapis.com/v1/public/yql";
$.ajax({
url:apiUrl,
data: {q: query},
dataType:"xml",
success:function(data, textStatus, jqXHR){
console.log(textStatus);
console.log(jqXHR);
console.log(data);
},
error: function(jqXHR, textStatus, errorThrown) {
console.log(textStatus);
console.log(jqXHR);
console.log(errorThrown);
}
});
});
</script>
<body>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment