一般是 NodeJS 和 JavaScript 的新手;如何进行基本文件 I/O?
read_and_edit_me.html
<!doctype html>
<html lang="en">
<head></head>
<body>
<a href="//foo">bar</a>
</body>
</html>
rw_dom.js
// Here is how I would do it if this was in <head></head>
document.open();
document.write('<a href="/bar">Out with the old -');
document.write('<a href="/new_bar">in</a> with the new!</a>');
var all_href = [], l = document.links;
document.close();
for (var i = 0; i < l.length; i++) {
all_href.push(l[i].href);
}
// `all_href` should contain: ["http://{host}/bar", "http://{host}/new_bar"]