-
-
Save zackshapiro/9a8d0c37676f4779afd36c70f98fd0a9 to your computer and use it in GitHub Desktop.
retreive a list of followers from twitter
This file contains hidden or 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