Last active
August 29, 2015 14:27
-
-
Save chenkie/60279ecc2e15406c4dc5 to your computer and use it in GitHub Desktop.
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
<!doctype html> | |
<html> | |
<head> | |
<title>Parse Google</title> | |
<script src="https://code.jquery.com/jquery-2.1.4.js"></script> | |
</head> | |
<body> | |
<ul id="links"></ul> | |
</body> | |
<!-- We can't access google.com directly due to the same-origin policy. To get around this we can use this helper script | |
which (I think) makes the request through a proxy. The script gives us an object that returns some useful properties --> | |
<script type="text/javascript" src="http://www.ajax-cross-domain.com/cgi-bin/ACD/ACD.js?uri=(http://www.google.com)"></script> | |
<script> | |
// One of the properties we get is responseText which is the HTML string from google | |
var google = ACD.responseText; | |
// We can use jQuery to turn the string into an object and at the same time find all <a> tags | |
var links = $(google).find('a'); | |
// We loop through all the <a> tags and for each one we append it to the #links ul above | |
$.each(links, function(index, link) { | |
$('#links').append('<li><a href=' + link + '>' + link + '</a></li>'); | |
}); | |
</script> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment