Advertisement
Guest User

Untitled

a guest
Jun 29th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. var getNumberOfItems = function(casper) {
  2. listItems = casper.evaluate(function () {
  3. var nodes = document.querySelectorAll('li');
  4. return Array.prototype.map.call(nodes, function(node) {
  5. return node.getAttribute('data-bt');
  6. });
  7. });
  8. casper.echo(listItems.length);
  9. return listItems.length;
  10. }
  11. casper.start(url, function() {
  12.  
  13. this.userAgent('Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html');
  14.  
  15. var js = this.evaluate(function() {
  16. return document;
  17. });
  18. var source = js.all[0].outerHTML;
  19.  
  20. if (source.match(/captcha/g)) {
  21. this.echo('Captcha found, logging in');
  22. this.evaluate(function() {
  23. document.getElementById("email").value="***";
  24. document.getElementById("pass").value="***";
  25. document.getElementById("loginbutton").children[0].click();
  26.  
  27. });
  28. }
  29. this.label('LOOP_START');
  30. var info = getNumberOfItems(this);
  31. this.scrollToBottom();
  32.  
  33. this.waitFor(function check(){
  34. casper.echo('waitFor');
  35. return info != getNumberOfItems(casper);
  36. }, function then(){
  37. casper.echo('then');
  38. if (getNumberOfItems(casper)<50) this.goto('LOOP_START');
  39. }, function onTimeout(){
  40. casper.echo("Timout reached");
  41. }, 20000);
  42.  
  43. casper.evaluate(function() {
  44. window.document.body.scrollTop = document.body.scrollHeight;
  45. });
  46.  
  47. casper.page.scrollPosition = { top: casper.page.scrollPosition["top"] + 4000, left: 0 };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement