trying to get prize from site

23 views
Skip to first unread message

Oscar Atienza

unread,
Jan 4, 2016, 6:28:08 AM1/4/16
to phantomjs
i am getting strange error .... like the same prize many times ... better with code ...

var mirarPagina = function() {
    console.log("miro pagina")
  page.open("mysite.com",function(status){
    if (status === "success") {
     var total = page.evaluate(function() {
         return jQuery("#priceId").text();
     });
     page.render("precio.jpg")
     
     console.log(total);
     setTimeout(function() {
         console.log("timeoutttttttt")
          mirarPagina();  
        }, 6000);
    });
  }else{
      console.log("Error abriendo pagina " + status);
      setTimeout(function() {
         console.log("timeoutttttttt")
          mirarPagina();  
        }, 6000);
    
  }

                });
    
};

i am getting 

first time 270
second timeout 270 270
third timeout 270 270 270 ..... and so on ... i dont know why it is stacking the calls :S

Oscar Atienza

unread,
Jan 4, 2016, 9:20:57 AM1/4/16
to phantomjs
it seems to work ok without includejs ..... but with include it multiplies ....


page test:


var page = require('webpage').create();
console.log('The default user agent is ' + page.settings.userAgent);
page.settings.userAgent = 'SpecialAgent';

var mirarPagina = function() { page.open('http://www.httpuseragent.org', function(status) {
  
  
  if (status !== 'success') {
    
    
    console.log('Unable to access network');
    setTimeout(function() {
mirarPagina()
}
,3000);
  } else {
    
        console.log("despues de incluirlo miro precio")
     var total = page.evaluate(function() {
         return jQuery("#myagent").text();
     });
   
    console.log(total);
    setTimeout(function() {
mirarPagina()
}
,3000);
  
  });
  }
});
}


setTimeout(function() {
mirarPagina()
}
,3000);

Manuel Seoane Capinha

unread,
Jan 4, 2016, 11:03:11 AM1/4/16
to phan...@googlegroups.com
For what it's worth, I've run into a similiar problem when including jQuery in a page that was already including it.
Now I test if jQuery was previsouly defined and only include it if really needed (this leaves a problem where some functionality may not be present on older versions of the lib ...)

Cheers,
Manuel

--
You received this message because you are subscribed to the Google Groups "phantomjs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to phantomjs+...@googlegroups.com.
Visit this group at https://groups.google.com/group/phantomjs.
For more options, visit https://groups.google.com/d/optout.

Oscar Atienza

unread,
Jan 5, 2016, 4:18:57 AM1/5/16
to phantomjs
It is not the jquery ... it fails too with sizzle .... 

var page = require('webpage').create();
console.log('The default user agent is ' + page.settings.userAgent);
page.settings.userAgent = 'SpecialAgent';

page.onConsoleMessage = function(msg) {
    console.log(msg);
};


page.onError = function(msg, trace) {

  var msgStack = ['ERROR: ' + msg];

  if (trace && trace.length) {
    msgStack.push('TRACE:');
    trace.forEach(function(t) {
      msgStack.push(' -> ' + t.file + ': ' + t.line + (t.function ? ' (in function "' + t.function +'")' : ''));
    });
  }

  console.error(msgStack.join('\n'));

};

var  i= 0;

var tiempo = function() {
  i=i+1;
  console.log("tiempo "+i)
  setTimeout(mirarPagina(),16000);
}

var mirarPagina = function() { page.open('http://www.httpuseragent.org', function(status) {
  
  
  if (status !== 'success') {
    
    
    console.log('Unable to access network');
   tiempo()
  } else {
    console.log("antes de injectar")
     if (page.injectJs('/var/lib/openshift/560264730c1e667ade00007d/app-root/data/sizzle.js')) {
        console.log("despues de incluirlo miro precio")
    var total = page.evaluate(function() {
         return Sizzle.getText(Sizzle("myagent"))
     });
   
    console.log(total);
   tiempo();
  
  } else {
    console.log("que pasoooooooo")
  }
  }
});
}



tiempo()

with this script when the network starts to fail (testing on openshift, perhaps it detects it is an attack to a server) it displays very fast the console.log("tiempo") and doesnt wait the timeout .... why? i dont know :(
Reply all
Reply to author
Forward
0 new messages