Created
June 13, 2024 11:43
-
-
Save pereayats/33da03380168480b9bb4a99232e60cab to your computer and use it in GitHub Desktop.
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 puppeteer = require('puppeteer') | |
const scrape = (async () => { | |
const browser = await puppeteer.launch({ headless: false }) | |
const page = await browser.newPage() | |
await page.goto('https://producthunt.com') | |
const product_links = await page.evaluate(() => { | |
const links = Array.from(document.querySelectorAll('a[data-test*="post-name-"]')) | |
return links.map(link => link.href) | |
}) | |
const products = [] | |
for (let link of product_links.slice(0, 3)) { | |
await page.evaluate((link) => { | |
document.querySelector('a[href="' + link?.replace('https://www.producthunt.com', '') + '"]')?.click() | |
}, link) | |
await page.waitForNetworkIdle() | |
const product = await page.evaluate(() => { | |
const title = document.querySelector('h1')?.innerText | |
const tagline = document.querySelector('h2')?.innerText | |
const makerBadge = document.querySelector('div[class*="styles_maker__"]') | |
const mainMakerDiv = makerBadge?.parentElement?.parentElement | |
const makerProfile = mainMakerDiv?.querySelector('a[href*="/@"]')?.href | |
return { title, tagline, makerProfile } | |
}) | |
await page.evaluate(() => { | |
document.querySelector('a[data-test="modal-close"]')?.click() | |
}) | |
products.push(product) | |
} | |
for (let product of products) { | |
await page.goto(product.makerProfile) | |
const maker = await page.evaluate(() => { | |
const name = document.querySelector('h1')?.innerText | |
return { name } | |
}) | |
console.log(maker) | |
product.maker = maker | |
} | |
console.log(products) | |
await browser.close() | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment