Need help grabbing all HTML after scripts finish loading
I’m new to Node.js and just got Puppeteer working. But I’m running into a problem. When I fetch the page, I only get the basic template without the info I need.
The page I’m trying to scrape loads content dynamically after a few seconds. I want to grab the data inside specific tags once everything is fully loaded.
I’d prefer a solution using vanilla JavaScript if possible since I’m not familiar with jQuery.
replace ‘.dynamic-content’ with a selector that appears when everythings loaded. this should give puppeteer time for all the js to run and populate the page.
I’ve encountered this issue before when scraping dynamic sites. One effective approach is to use Puppeteer’s page.evaluate() method to run JavaScript directly in the browser context after the page loads. This allows you to wait for specific elements or conditions before extracting content.
This waits until there are more than 10 ‘strong’ elements before returning the full HTML. Adjust the condition as needed for your specific case. Hope this helps!
I’ve dealt with this exact problem when scraping dynamic sites. One trick that worked well for me was using Puppeteer’s waitForFunction() method. It lets you define a custom condition to wait for before proceeding.
This waits up to 10 seconds for the page to have more than 40 ‘strong’ elements before grabbing the content. You can adjust the selector and count to match what you’re expecting on the fully loaded page.
Also, make sure your browser isn’t running in headless mode - some sites detect that and serve different content. Adding {headless: false} to your puppeteer.launch() options might help if nothing else works.