Como posso esperar que uma conexão socket.io retorne dados usando o casperJS?
Estou raspando uma página que usa socket.io para preencher algumas opções de seleção de tags. Como posso esperar pelo soquete receber dados antes de avaliar a página? estou usandocasperJS
o código do soquete (carregado pelo site de destino):
socket.on('list', function (data) {
$.each(data.match_names, function (id, name) {
if (some condition) {
/*nothing*/
} else {
if (typeof( varname ) == 'function') {
$('#myselector').append('<option value="' + id + '">' + name + " " + get_tournament_name(id.substr(0, 4)) + '</option>');
} else {
$('#myselector').append('<option value="' + id + '">' + name + '</option>');
}
match_count++;
}
});
Verifico se o script socket.io foi carregado:
casper.waitForResource("socket.io.js", function() {
this.echo('socket.io has been loaded.'); //is printed
//how can I check that data has arrived from 'socket.on('list', function (data)' ?
});
Mas as tags de opção não estão na página, provavelmente porque estou avaliando a página muito cedo
casper.then(function() {
baseTargetUrl = this.evaluate(function() {
return __utils__.getElementByXPath('//*[@id="wrapper"]/div[1]/a[2]')["href"];
});
console.log('logging: '+baseTargetUrl); // works
casper.thenOpenAndEvaluate(baseTargetUrl ,function() { //baseTargetUrl is no longer undefined, it's a closure now
$(function(){ // DOM is ready
var myOptions = [] ;
$('select#myselector option').each(function(){
myOptions.push( $(this).text() + ' : '+$(this).val() ); //additional options have not yet been added
});
});
});
});