What? Bored of server member counts and wanna show Instagram Followers Count now? Cool, I used autocode puppeteer to go to a instagram followers tracker site as scraping Instagram is against their policy. Click add to project instead of copy pasting as there is stuffs you need to add to your environment variables. After that, it should be working pretty well once you clicked run for once:) if you want it to update more frequently, just change the sceduler frequency:) Please to change your timeout execution to 30000ms
// authenticates you with the API standard library
// type `await lib.` to display API autocomplete
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
//require autocode-puppeteer as puppeteer is a large dependency to add.
const puppeteer = require('autocode-puppeteer');
//defines sleep function
let sleep = async (ms) => {
return new Promise((resolve) => {
setTimeout(resolve, ms);
});
};
//your Instagram Username
const username = `${process.env.USERNAME}`;
//defines browser as nothing:)
let browser;
//try this code first
try {
//define browser as launching a browser:)
browser = await puppeteer.launch();
console.log('browser launched');
//opens a new page/tab
const page = await browser.newPage();
console.log('new page created');
//goes to the Instagram Follower Count Tracker website
await page.goto('https://www.insfollowup.com/instagram-followers-counter');
console.log('tabs opened');
//click on the input field so that we can type on it
await page.click("[type='text']");
//type in the field with our username
await page.type("[type='text']", `${username}`);
console.log('username inputted');
//clicks on the check now button to check for the username
await page.click('.checkAccount');
console.log('check account follower button clicked');
//waits for 8 seconds to ensure that the page is able to find the Instagram username
await sleep(8000);
//makes sure that isVisible Function is able to find a text called Realtime Followers
await isVisible(page, '.user-details-counter > :nth-child(1)');
console.log('Realtime Followers text is visible');
//defines FollowerCount as getText function which gets the text from the selector of `.followers-counter-counter dt`
let FollowerCount = await getText(page, '.followers-counter-counter dt');
console.log('success!');
//updates your Instagram Follower Count
await lib.discord.channels['@0.2.2'].update({
channel_id: `${process.env.VOICE_CHANNEL_ID}`,
name: `IG Follower Count: ${FollowerCount}`,
});
}
//catch errors if any
catch (e) {
console.log('error occurred: ', e);
}
//finally if browser is opened, close it.
finally {
if (browser) {
await browser.close();
}
}
//Essential Functions
async function isVisible(page, selector) {
try {
const elementHandle = await page.$(selector);
if (!elementHandle) {
return false;
}
const elementBox = await elementHandle.boundingBox();
return Boolean(elementBox);
} catch (err) {
return false;
}
}
function getText(page, selector) {
return page.evaluate((selector) => {
const element = document.querySelector(selector);
return element.innerText;
}, selector);
}