Created
October 11, 2018 18:46
-
-
Save Pompeu/9e71308980e51783f8e73d5276ee9d6e to your computer and use it in GitHub Desktop.
crow_ibov.js
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
| 1 const alpa = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'Y', 'X', 'Z', '0', '1', '2', '3', '4 ', '5', '6', '7', '8', '9']; | |
| 2 | |
| 3 const rx = require('rx') | |
| 4 const request = require('request') | |
| 5 const cherio = require('cherio') | |
| 6 | |
| 7 const url = x => | |
| 8 `http://cvmweb.cvm.gov.br/SWB/Sistemas/SCW/CPublica/CiaAb/FormBuscaCiaAbOrdAlf.aspx?LetraInicial=${x}` | |
| 9 | |
| 10 const load = cherio.load | |
| 11 | |
| 12 rx.Observable | |
| 13 .fromArray(alpa) | |
| 14 .flatMap(x => rx.Observable.fromEvent(request.get(url(x)), 'data')) | |
| 15 .map(x => x.toString('utf8')) | |
| 16 .map(load) | |
| 17 .flatMap($ => Array.from($('#dlCiasCdCVM > tbody > tr > td:nth-child(4)')) | |
| 18 .filter(x => !!Number($(x).text())) | |
| 19 .map(x => Number($(x).text())) | |
| 20 ) | |
| 21 //.map(x => x.sort((a, b) => a > b ? 1 : -1)) | |
| 22 .subscribe(x => console.log(x) | |
| 23 , err => console.error(err) | |
| 24 , () => console.log('done')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment