Created
October 24, 2024 01:31
-
-
Save aaronfay/8ea946ba9de92b5ef98fe1125c7c1a36 to your computer and use it in GitHub Desktop.
Scrape Facebook company reviews
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
// should be run in the developer console | |
async function wait(time=50) { | |
await new Promise(resolve => { | |
setTimeout(() => { | |
resolve('Done'); | |
}, time); | |
}); | |
} | |
reviews = Array.from(document.querySelectorAll('.x1yztbdb.x1n2onr6')) | |
const output = [] | |
for (const review of reviews) { | |
review.scrollIntoView() | |
await wait(100) | |
const title = review.querySelector('.html-h2').innerText | |
console.log(title) | |
const span = Array.from(review.querySelectorAll('.html-span'))[3] | |
let comments | |
if (span && !span.innerText.includes('comment')) { | |
comments = span.innerText | |
console.log(comments) | |
} else { | |
const div = review.querySelector('.html-div [data-ad-preview="message"]') | |
if (div) { | |
comments = div.innerText | |
console.log('div', comments) | |
} else { | |
comments = '--none--' | |
console.log('no div') | |
} | |
} | |
output.push({title, comments}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment