I am scraping a list of users who liked a post on instagram. The following code runs perfectly fine:
await click(post);
await sleep(500);
var users = await findAll(user);
var userNames = users.map(async user => {
var userNameText = await user.getText();
return userNameText;
});
var result = await Promise.all(userNames);
console.log(result); // ['user1', 'user2'...]
But the modal with the likes only shows 10 users initially. To see the other users, you have to keep scrolling while it only loads a subset at a time. The following recursive function keeps scrolls down loading a single user incrementally for the number of users I want to get:
let likers = [];
await (async function theLoop(i) {
await driver.sleep(400);
findAll(user).then(async t => {
let liker = await t[8].getText();
await scroll(find(modal)); //Scroll inside the modal
await likers.push(liker); //PUSH LIKER TO ARRAY
console.log(liker);
if (--i) {
theLoop(i);
}
});
})(60);
The problem is that I am unable to get the list of all users from this function. If I do a console.log(likers) if fires immediately before the array is populated. same happens with any function I run after this recursive loop. Nothing I do works.
tan array of all users? (good variable names can be helpful). Whyt[8]?