Answer the question
In order to leave comments, you need to log in
Why is only 1 link displayed as a result, and not all?
There is a code:
io.sockets.on('connection', function(socket) {
var group = 'fnatic';
var url = 'http://steamcommunity.com/groups/' + group + '#members';
request(url, function(err, resp, body){
$ = cheerio.load(body);
links = $('a');
$(links).each(function(i, link){
// console.log($(link).attr('href'));
var users = $(link).attr('href');
socket.emit('hatler', users);
});
});
});
var socket = io.connect('http://localhost:3000');
socket.on('hatler', function(users) {
$('.result').html(users);
});
Answer the question
In order to leave comments, you need to log in
You send each user as a separate message, collect them in an array and send this array after .each()
UPD
io.sockets.on('connection', function(socket) {
var group = 'fnatic';
var url = 'http://steamcommunity.com/groups/' + group + '#members';
request(url, function(err, resp, body){
$ = cheerio.load(body);
links = $('a');
var users = [];
$(links).each(function(i, link){
// console.log($(link).attr('href'));
users.push($(link).attr('href'));
});
socket.emit('hatler', users);
});
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question