Skip to content

Instantly share code, notes, and snippets.

@heaversm
Created December 20, 2023 01:04
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save heaversm/5507951271341616ea07648614360af1 to your computer and use it in GitHub Desktop.
Save heaversm/5507951271341616ea07648614360af1 to your computer and use it in GitHub Desktop.
chatGPT generated puppeteer scraper code
const puppeteer = require('puppeteer');
async function fillForm(data) {
const browser = await puppeteer.launch({ headless: true });
const page = await browser.newPage();
for (const item of data) {
await page.goto('YOUR_WEBPAGE_URL'); // Replace with your webpage URL
// Click the first "Select" button
await page.click('button.select-button'); // Replace with the correct selector
// Populate the "Name" field
await page.type('input#name', item.podcastName); // Replace with the correct selector
// Wait for the results to load and check if there are any results
try {
await page.waitForSelector('.result-item', { timeout: 5000 }); // Adjust selector and timeout as needed
await page.click('.result-item'); // Clicks the first matching result
} catch (error) {
console.log(`No matching results for ${item.podcastName}, skipping...`);
continue; // Skip to the next item if no results
}
// Select the first episode
await page.select('select#episode', 'firstValue'); // Replace with correct selector and value
// Wait for the success message
await page.waitForSelector('.success-message'); // Adjust selector as needed
// Click the "PodQuest" link to go back to the home page
await page.click('a#podquest-home'); // Replace with the correct selector
}
await browser.close();
}
// Sample data array
const data = [
{
"podcastName": "The Joe Rogan Experience",
},
// Add more items here
];
fillForm(data).catch(console.error);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment