-
-
Save samverneck/76aac1ddf73ac9a44c6246bf78fdc9dd to your computer and use it in GitHub Desktop.
Pega e salva os conteúdos da MDN
This file contains hidden or 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
const cheerio = require('cheerio') | |
const rp = require('request-promise') | |
const links = require('./links') | |
const createFile = require('./createFile') | |
const options = { | |
uri: `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/`, | |
transform: (body) => cheerio.load(body), | |
} | |
const BASE = `https://developer.mozilla.org/` | |
rp(options) | |
.then( ($) => { | |
$(`#wikiArticle ul li a`) | |
.map(( index, element ) => element.attribs.href ) | |
.get() // | |
.map( ( el, i ) => { | |
const _name = el.split('Reference/')[1] | |
const name = (_name) ? _name.replace('/', '_') : i | |
const link = BASE+el | |
return { name, link } | |
}) | |
.map( content => | |
rp( { | |
uri: content.link, | |
transform: (body) => cheerio.load(body), | |
}) | |
.then( ($) => | |
createFile(`conteudos/${content.name}.html`, | |
$(`#wikiArticle`).html()) ) | |
.catch( (err) => | |
console.log('err no request', err) ) | |
) | |
} | |
) | |
.catch( (err) => console.log('err no request', err) ) | |
// } ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment