Created
May 28, 2017 09:23
-
-
Save unycone/f325c4d06abeb1df78db32f51538805a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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