I use casperjs for grab some test.
Algorithm is open URL parse page, click button for load next page. How to grab next pages until test is complete. All question get random and I don't now next question before form submitted.
I need parse pages like a cycle or recursive. My code is:
casper.start(startUrl, function () {
this.click('#training');
this.evaluate(function () {
$('input[type="submit"]:first').click();
});
});
casper.then(function () {
var currentUrl = this.getCurrentUrl(),
startIdPos = currentUrl.indexOf('=') + 1,
questionId = currentUrl.slice(startIdPos),
content = $(this.getHTML()),
answers = [],
question,
startCorrectAnswerPos = content.find('script:nth-child(2)').html().indexOf('var bc='),
correctAnswer = content.find('script:nth-child(2)').html().slice(startCorrectAnswerPos + 8, startCorrectAnswerPos + 9);
question = content.find('table.quizz p.qw').html();
console.log(">>>>>>" + this.getCurrentUrl());
this.fill('form', {
'answer': correctAnswer
}, true);
});
casper.run();
This code complete parse only one page, but doesn't redirect to next page and parse it. What I do wrong?