jweinst1
8/25/2016 - 7:40 PM

experimentscraper.js

//experimenting with html strings

var hstring = "<b><c>not good.</c><g><h><h>1</h><h><h>1</h></h></h><h>1</h></g><a>This is wonderful</a></b>";

//creates a nested string list from the XML/HTML string
function makeList(string){
	var filtered = [];
	var splits = string.split(/(<[^<>]+>)|(<\/[^<>]+>)/);
	for(var i=0;i<splits.length;i++){
		if(splits[i]){
			if(splits[i][0] === "<" && splits[i].slice(-1) === ">"){
				if(splits[i][1] === "/"){
					filtered.push("]");
					filtered.push(",");
				}
				else {
					filtered.push("[");
				}
			}
			else {
				filtered.push('"' + splits[i] + '"');
			}
		}
	}
	//must use eval to create js array
	return eval(filtered.slice(0, -1).join(""));
}