Last active
September 23, 2018 23:23
-
-
Save GPrimola/2bb91dadb54bc1b647cc2d8d7bf9bf8b to your computer and use it in GitHub Desktop.
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
| // Colocar linha por linha no console do navegador (preferência Google Chrome) | |
| // Tutorial Google Chrome JS Console: https://developers.google.com/web/tools/chrome-devtools/console/?hl=pt-br | |
| // iCarros | |
| $('h3.direita.preco_anuncio').map((i, v) => v.innerHTML).map((i,v) => v.match(/\d{2}\.\d{3}/gi)).map((i,v) => v.replace('.', '')).map((i,v) => parseInt(v)) | |
| // WebMotors | |
| $('.advert .price-novo').map((i, v) => v.innerHTML).map((i,v) => v.match(/\d{2}\.\d{3}/gi)).map((i,v) => v.replace('.', '')).map((i,v) => parseInt(v)) | |
| // A única coisa chata é que tem que rodar página por página, pois a aplicação é malfeita e o link de paginação | |
| // não guarda a busca feita, tem um mecanismo próprio de paginação que não dá para um robô seguir | |
| // Depois de coletar todos os preços: | |
| var soma = (a, b) => a + b | |
| var precos = [25520, 25900, 25900, 26320, 26900, 27000, 27290, 27500, 27890, 27900, 27990, 27990, 27999, 28490, 28900, 28990, 29450, 29500, 29800, 29800, 29900, 29900, 29900, 29900, 29900, 29900, 29950, 29990, 29990, 29990, 29990, 29990, 29990, 30000, 30093, 30700, 30890, 30900, 30950, 30990, 30990, 30990, 30990, 30990, 30990, 30990, 31000, 31000, 31000, 31000, 31490, 31500, 31500, 31900, 31900, 31900, 31900, 31900, 31900, 31900, 31900, 31900, 31990, 31990, 31990, 31990, 32000, 32000, 32000, 32000, 32500, 32500, 32500, 32500, 32800, 32890, 32890, 32890, 32900, 32900, 32900, 32900, 32900, 32900, 32900, 32900, 32900, 32900, 32900, 32900, 32900, 32900, 32900, 32900, 32900, 32900, 32990, 32990, 32990, 32990, 32990, 32990, 32990, 32990, 32990, 33000, 33000, 33500, 33500, 33500, 33500, 33540, 33799, 33800, 33800, 33900, 33900, 33900, 33900, 33900, 33900, 33900, 33900, 33900, 33900, 33900, 33900, 33900, 33980, 33990, 33990, 33990, 33990, 34290, 34500, 34789, 34890, 34900, 34900, 34900, 34900, 34900, 34900, 34900, 34900, 34990, 34990, 34990, 34990, 35000, 35000, 35890, 35899, 35900, 35900, 35900, 35900, 35900, 35900, 35900, 35900, 35990, 36900, 36990, 37900, 37900, 37990, 38900, 39000, 39935] | |
| var mediaPrecos = parseFloat(precos.reduce(soma, 0)) / parseFloat(precos.length) | |
| console.log(`Preço médio: R$ ${mediaPrecos}`) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment