The sample code below currently gets an HTML page, and tries to read it into an array. The AJAX is working perfectly, and I can get a nodelist object successfully. Is it possible to somehow read this page into an array and not one singular object? Eventually I need to pull out every single member of this array individually as I am attempting in the for loop below:
$.ajax({
url: "/thePageToScrape.html",
dataType: 'text',
success: function(data) {
var elements = $("<div>").html(data)[0].getElementsByTagName("body");
for(var i = 0; i < elements.length; i++) {
var theText = elements.firstChild.nodeValue;
// Do something here
}
}
});
elementsis not an array, but a NodeList instance, there's a difference!Array.prototype.slice.apply(elements, [0]);turns it into an array