Skip to content

Instantly share code, notes, and snippets.

@mtliendo
Created October 14, 2020 21:05
Show Gist options
  • Save mtliendo/012a84e5cbd3d74b1f178cbc43685266 to your computer and use it in GitHub Desktop.
Save mtliendo/012a84e5cbd3d74b1f178cbc43685266 to your computer and use it in GitHub Desktop.
retreive a list of followers from twitter
const cheerio = require('cheerio')
const axios = require('axios').default
async function fetchFollowerCounts(usernames) {
const followerData = usernames.map((username) => {
return axios.get(`https://mobile.twitter.com/${username}`).then((res) => {
const $ = cheerio.load(res.data)
const searchContext = `a[href='/${username}/followers']`
const followerCountString = $(searchContext)
.text()
.match(/[0-9]/gi)
.join('')
return { user: username, followerCount: Number(followerCountString) }
})
})
return Promise.all(followerData)
}
fetchFollowerCounts(['mtliendo', '_mallorybrewer_'])
exports.handler = fetchFollowerCounts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment