Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var getNumberOfItems = function(casper) {
- listItems = casper.evaluate(function () {
- var nodes = document.querySelectorAll('li');
- return Array.prototype.map.call(nodes, function(node) {
- return node.getAttribute('data-bt');
- });
- });
- casper.echo(listItems.length);
- return listItems.length;
- }
- casper.start(url, function() {
- this.userAgent('Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html');
- var js = this.evaluate(function() {
- return document;
- });
- var source = js.all[0].outerHTML;
- if (source.match(/captcha/g)) {
- this.echo('Captcha found, logging in');
- this.evaluate(function() {
- document.getElementById("email").value="***";
- document.getElementById("pass").value="***";
- document.getElementById("loginbutton").children[0].click();
- });
- }
- this.label('LOOP_START');
- var info = getNumberOfItems(this);
- this.scrollToBottom();
- this.waitFor(function check(){
- casper.echo('waitFor');
- return info != getNumberOfItems(casper);
- }, function then(){
- casper.echo('then');
- if (getNumberOfItems(casper)<50) this.goto('LOOP_START');
- }, function onTimeout(){
- casper.echo("Timout reached");
- }, 20000);
- casper.evaluate(function() {
- window.document.body.scrollTop = document.body.scrollHeight;
- });
- casper.page.scrollPosition = { top: casper.page.scrollPosition["top"] + 4000, left: 0 };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement