schickling/chromeless

Loop Through List of Webpages and Click a Button

Aberta

#361 aberto em 12 de dez. de 2017

 (0 comentário) (0 reação) (0 responsável)TypeScript (606 forks)batch import
help wantedquestion

Métricas do repositório

Stars
 (13.240 estrelas)
Métricas de merge de PR
 (Nenhuma PRs mesclada em 30d)

Description

Hey I'm wondering why my code isn't working. I'm trying to loop through a list of URLs and click a button on each page and then wait for a success message. However, I'm getting a "not opened" error after the first one succeeds. Here's my code and the data2.csv is just a list of URLs:

const { Chromeless } = require('chromeless');
const LineByLineReader = require('line-by-line');

var fs = require('fs');
var util = require('util');
var logFile = fs.createWriteStream('log.txt', { flags: 'a' });
// Or 'w' to truncate the file every time the process starts.
var logStdout = process.stdout;

console.log = function () {
    logFile.write(util.format.apply(null, arguments) + '\n');
    logStdout.write(util.format.apply(null, arguments) + '\n');
}
console.error = console.log;

async function run() {
    const chromeless = new Chromeless();
    const lr = new LineByLineReader('dump2.csv');
    lr.on('line', function (line) {
        console.log(line);
        lr.pause();
        chromeless
            .goto(JSON.parse(JSON.stringify(line)))
            .evaluate(() => {
                console.log('hey');
            })
            .click('.loan-details li button')
            .wait('#alerts .alert')
            .end()
            .then(() => {
                lr.resume();
            })
            .catch((error) => {
                console.log(error);
                lr.resume();
            });
        // 'line' contains the current line without the trailing newline character.
    });

    lr.on('end', function () {
        chromeless.end()
        // All lines are read, file is closed now.
    });
}

run().catch(console.error.bind(console))

Guia do colaborador