Rosetta Code:Village Pump/tasks descriptions only: Difference between revisions

SlimerJS solution
No edit summary
(SlimerJS solution)
Line 45:
 
::The while loop should handle the different amounts of text between the infobox markup and the beginning of the contents table. [[User:Axtens|Axtens]] ([[User talk:Axtens|talk]]) 09:53, 16 April 2015 (UTC)
 
::Here's a SlimerJS solution. Not perfect but seems to work reasonably well. A little annoyingly, it doesn't implement innerText.
<lang javascript>var fs = require('fs');
 
function innerCall(nam, ref) {
var ipage = require("webpage").create();
ipage.open(ref, function () {
var description = ipage.evaluate( function () {
var start = document.getElementsByClassName("infobox")[0];
var cursor = start.nextElementSibling;
var desc = "";
while (cursor.tagName !== "TABLE") {
there = cursor;
desc = desc + there.innerHTML + "\n";
cursor = cursor.nextElementSibling;
}
return desc;
});
var fileName = nam + ".txt";
fileName = fileName.replace(/\//g,"_");
fs.write(fileName,description);
//console.log(nam + " " + ref + "\n" + description);
ipage.close();
});
}
 
 
var page = require("webpage").create();
page.open("http://rosettacode.org/wiki/Category:Programming_Tasks", function () {
var anchors = page.evaluate(function () {
return document.getElementById("mw-pages").getElementsByTagName("a");
});
for (var i = 0; i < anchors.length; i++ ) {
//console.log(anchors[i].innerHTML + ' ' + anchors[i].href);
innerCall(anchors[i].innerHTML, anchors[i].href);
slimer.wait(100);
}
page.close();
//phantom.exit();
});</lang>
 
I would have used PhantomJs but had trouble building it and lost patience rapidly.
[[User:Axtens|Axtens]] ([[User talk:Axtens|talk]]) 15:21, 16 April 2015 (UTC)
Anonymous user