Skip to content

Instantly share code, notes, and snippets.

@unycone
Created May 28, 2017 09:23
Show Gist options
  • Save unycone/f325c4d06abeb1df78db32f51538805a to your computer and use it in GitHub Desktop.
Save unycone/f325c4d06abeb1df78db32f51538805a to your computer and use it in GitHub Desktop.
var wikipedia = require('node-wikipedia');
var getMatches = function(string, regex)
{
var matches = [];
var match = null;
while (match = regex.exec(string)) {
var ary = [];
match.forEach(function(e, i) {
if (i > 0) {
ary.push(e);
}
});
matches.push(ary);
}
return matches;
}
var processResponse = function(resp)
{
if (resp != null && resp["wikitext"]["*"] != null) {
console.log("resp != null");
var str = resp["wikitext"]["*"];
var regexp = /\| (.+) \= (.+)/gm;
var match = getMatches(str, regexp);
match.forEach(function(e, i) {
console.log(i + " : " + e[0] + " = " + e[1]);
});
}
}
// notice: save this file in UTF-8 if you query 2byte characters
wikipedia.page.data("柴咲コウ", {content: true, wikitext: true, lang: 'ja'}, function(resp) { processResponse(resp); });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment