'Can't get member count and daily post count in a Facebook group using puppeteer
Been trying to get the member count and daily post count of different Facebook groups. Kept getting null or TypeError. Got those query selectors when I copied the selector from chrome.
const puppeteer = require('puppeteer')
const fs = require('fs')
// get the amount of members
const start = async () => {
const browser = await puppeteer.launch()
const page = await browser.newPage()
await page.goto('https://www.facebook.com/groups/free.code.camp.world')
const memberCount = await page.evaluate(() => {
return document.querySelector("#mount_0_0_Hj > div > div:nth-child(1) > div > div.rq0escxv.l9j0dhe7.du4w35lb > div > div > div.j83agx80.cbu4d94t.d6urw2fd.dp1hu0rb.l9j0dhe7.du4w35lb > div.l9j0dhe7.dp1hu0rb.cbu4d94t.j83agx80 > div:nth-child(1) > div.rq0escxv.l9j0dhe7.du4w35lb.j83agx80.pfnyh3mw.taijpn5t.gs1a9yip.owycx6da.btwxx1t3.ihqw7lf3.cddn0xzi > div > div > div > div > div:nth-child(1) > div > div > div > div > div > div:nth-child(2) > span > div > div:nth-child(3) > a").textContent
})
// get the amount of daily posts
const dailyPost = await page.evaluate(() => {
return document.querySelector("#mount_0_0_Hj > div > div:nth-child(1) > div > div.rq0escxv.l9j0dhe7.du4w35lb" +
" > div > div > div.j83agx80.cbu4d94t.d6urw2fd.dp1hu0rb.l9j0dhe7.du4w35lb >" +
" div.l9j0dhe7.dp1hu0rb.cbu4d94t.j83agx80 > div.j83agx80.cbu4d94t.buofh1pr > div > div:nth-child(2) >" +
" div > div > div > div:nth-child(3) > div > div > div > div > div > div:nth-child(2) > div >" +
" div:nth-child(1) > div > div > div.rq0escxv.l9j0dhe7.du4w35lb.j83agx80.cbu4d94t.d2edcug0.hpfvmrgz.rj1gh0hx.buofh1pr.g5gj957u.o8rfisnq.p8fzw8mz.pcp91wgn.iuny7tx3.ipjc6fyt > div > div:nth-child(1) > span").textContent
})
console.log(memberCount)
console.log(dailyPost)
await browser.close()
}
start()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
