Created
October 14, 2020 21:05
-
-
Save mtliendo/012a84e5cbd3d74b1f178cbc43685266 to your computer and use it in GitHub Desktop.
retreive a list of followers from twitter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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