Created
December 10, 2019 17:49
-
-
Save rgsoto/c8d3ca24425eb5376ce9f7c47df55670 to your computer and use it in GitHub Desktop.
wikp
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
#!/usr/local/bin/node | |
// Returns the paragraphs from a wikipedia link, stripped of reference numbers. | |
let request = require("request"); | |
let url = process.argv[2]; | |
const jsdom = require("jsdom"); | |
const { JSDOM } = jsdom; | |
request(url, function(error, response, body) { | |
//simulate a document object model. | |
let { document } = (new JSDOM(body)).window; | |
// Grab all the paragraphs and references. | |
let paragraphs = document.querySelectorAll("p"); | |
let references = document.querySelectorAll(".reference"); | |
// Remove any references. | |
references.forEach(function(reference){ | |
reference.remove(); | |
}); | |
// Print out all of the paragraphs. | |
paragraphs.forEach(function(paragraph) { | |
console.log(paragraph.textContent); | |
}) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment