Skip to content

Instantly share code, notes, and snippets.

@pocari
Created November 10, 2012 06:46
Show Gist options
  • Save pocari/4050215 to your computer and use it in GitHub Desktop.
Save pocari/4050215 to your computer and use it in GitHub Desktop.
html parse sample
var fso = new ActiveXObject("Scripting.FileSystemObject");
function with_openfile(path, action) {
var f = null;
try {
f = fso.openTextFile(path);
return action(f);
} finally {
if (f) {
f.close();
}
}
}
function get_domdocument_from_file(path) {
return with_openfile(path, function (f) {
return get_domdocument(f.readAll())
});
}
function get_domdocument(contents) {
var document = WScript.CreateObject("htmlfile");
document.write(contents);
return document;
}
function main() {
var document = get_domdocument("<table><tr><td>1</td></tr></table>");
var nodes = document.getElementsByTagName("td");
var str = "";
for (var i = 0; i < nodes.length; i++) {
str += nodes[i].innerText + "\n";
}
WScript.Echo(str);
}
WScript.quit(main());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment