Prompt
website scraping with javascript rendering
Latest observation
Oct 4, 2026
OpenAI APIWeb search: off
If you need to scrape a website that relies on JavaScript rendering (content appears after the initial HTML loads), you generally need a browser automation tool instead of a simple HTTP request scraper.
Good options
1. Playwright
Best modern choice for dynamic sites.
Install:
npm install playwright
Example:
const { chromium } = require('playwright');
(async () => {
const browser = await chromium.launch({ headless: true });
const page = await browser.newPage();
await page.goto('https://example.com', { waitUntil: 'networkidle' });
const content = await page.textContent('body');
console.log(content);
await browser.close();
})();
2. Puppeteer
Also very common, especially in Node.js.
Install:
npm install puppeteer
Example:
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch({ headless: true });
const page = await browser.newPage();
await page.goto('https://example.com', { waitUntil: 'networkidle2' });
const text = await page.evaluate(() => document.body.innerText);
console.log(text);
await browser.close();
})();
Tips for scraping JS-rendered pages
- Use
waitUntil: 'networkidle'or wait for a specific selector:await page.waitForSelector('.target-class'); - If data is loaded via API calls, it’s often easier to scrape the API directly.
- Some sites render content lazily, so you may need to scroll:
await page.evaluate(() => window.scrollTo(0, document.body.scrollHeight)); - Add delays if needed:
await page.waitForTimeout(2000);
If you want something simpler
For lightweight rendering, you can use:
- JSDOM for parsing HTML only (no real JS execution)
- Cheerio for HTML parsing after you already fetched rendered content
Important note
Make sure scraping is allowed by the site’s:
- Terms of Service
- robots.txt
- legal/privacy restrictions
If you want, I can give you:
- a complete scraper template,
- a Python Selenium version, or
- help scraping a specific website.