Skip to content

Instantly share code, notes, and snippets.

@mallendeo
Last active August 29, 2015 14:23
Show Gist options
  • Save mallendeo/e780c00db5119ff9a4c4 to your computer and use it in GitHub Desktop.
Save mallendeo/e780c00db5119ff9a4c4 to your computer and use it in GitHub Desktop.
Parse external DOM with js
function getParsedDOM(url, callback) {
var request = new XMLHttpRequest()
request.open('GET', url, true)
request.onload = function() {
if (this.status >= 200 && this.status < 400) {
var parser = new DOMParser();
var doc = parser.parseFromString(this.response, "text/html");
return callback(doc)
}
}
request.send()
}
(function() {
getParsedDOM('https://www.google.com', function(data) {
console.log(data.querySelector('title').textContent)
})
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment