Skip to content

Commit

Permalink
Merge pull request #8 from Menighin/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Menighin committed Jun 13, 2020
2 parents 3794cce + c07510d commit 0b93aa2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ Na criação de um `CeiCrawler` é possivel especificar alguns valores para o pa
|---------------------|-----------|---------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| **puppeteerLaunch** | _Object_ | _{}_ | Esse objeto é passado ao método `launch` do `Puppeteer`. As opções estão listadas [aqui](https://github.com/puppeteer/puppeteer/blob/v2.1.1/docs/api.md#puppeteerlaunchoptions). |
| **capDates** | _Boolean_ | _false_ | Se `true`, as datas utilizadas de input para buscas serão limitadas ao range de datas válidas do CEI, impedindo que ocorra um erro caso o usuário passe uma data maior ou menor. |
| **loginTimeout** | _Number_ | 35000 | Tempo, em ms, que o crawler espera o login concluir antes de considerar erro. Diversas vezes, como a noite e aos fins de semana, o sistema do CEI parece ficar muito instavél e causa diversos timeouts.
| **trace** | _Boolean_ | _false_ | Printa mensagens de debug no log. Útil para desenvolvimento. |

Exemplo:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cei-crawler",
"version": "0.2.0",
"version": "0.2.1",
"description": "Crawler para pegar dados do Canal Eletronico do Investidor",
"main": "src/app.js",
"repository": {
Expand Down
10 changes: 8 additions & 2 deletions src/lib/CeiCrawler.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ class CeiCrawler {
this.username = username;
this.password = password;
this.options = options;
this._setDefaultOptions();
}

_setDefaultOptions() {
if (!this.options.trace) this.options.trace = false;
if (!this.options.loginTimeout) this.options.loginTimeout = 35000;
}

async _login() {
Expand All @@ -59,15 +65,15 @@ class CeiCrawler {
await PuppeteerUtils.waitForAny([
{
id: 'nav',
pr: this._page.waitForNavigation({timeout: 40000})
pr: this._page.waitForNavigation({ timeout: 1000 * 60 * 10 }) // 10 minutes tops
},
{
id: 'fail',
pr: this._page.waitForSelector('.alert-box.alert')
},
{
id: 'fail',
pr: this._page.waitFor(35000) // After 35s, consider the login has failed
pr: this._page.waitFor(this.options.loginTimeout) // After the time specified, consider the login has failed
}
]).then(async id => {
if (id === 'fail')
Expand Down

0 comments on commit 0b93aa2

Please sign in to comment.