Last active
February 28, 2020 21:43
-
-
Save JoelLisenby/24fd8dc73ce08fe16577194b859a3453 to your computer and use it in GitHub Desktop.
WP-JSON HTML Parser
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> | |
<script> | |
const req = new XMLHttpRequest(); | |
req.addEventListener('load', function(e) { | |
var response = JSON.parse( e.target.response ); | |
var page_html = response.content.rendered; | |
let domparser = new DOMParser(); | |
let doc = domparser.parseFromString(page_html, 'text/html' ); | |
console.log( doc.body.children[0].rows ); | |
doc.body.children[0].rows.forEach((element) => { | |
console.log(element); | |
numCallbackRuns++; | |
}); | |
}); | |
req.open('GET', '[siteurl]/wp-json/wp/v2/pages/[pageid]'); | |
req.send(); | |
</script> | |
</head> | |
<body></body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment