Prompt
How do I scrape a dynamic website that loads content with JavaScript?
Latest observation
Oct 26, 2026
OpenAI APIWeb search: off
To scrape a website that loads content with JavaScript, you usually need a tool that can render the page like a browser, not just download the raw HTML.
Common approaches
1. Use a headless browser
Tools like:
- Playwright (recommended)
- Selenium
- Puppeteer
These open the page, run JavaScript, and let you extract the rendered content.
Example with Playwright (Python)
from playwright.sync_api import sync_playwright
with sync_playwright() as p:
browser = p.chromium.launch(headless=True)
page = browser.new_page()
page.goto("https://example.com", wait_until="networkidle")
html = page.content()
print(html)
browser.close()
Then you can use BeautifulSoup or similar to parse html.
2. Inspect network requests
Often the page itself is just a shell, and JavaScript fetches data from an API.
Open DevTools in your browser:
- Go to the Network tab
- Reload the page
- Look for:
fetch/XHRrequests- JSON responses
- API endpoints
If you can find the API directly, scraping becomes much easier and faster than browser automation.
Example idea
Instead of scraping rendered HTML:
import requests
r = requests.get("https://example.com/api/items")
data = r.json()
print(data)
3. Wait for dynamic content
Sometimes content appears after a delay. You may need to wait for a selector.
Playwright example
page.goto("https://example.com")
page.wait_for_selector(".item")
items = page.locator(".item").all_text_contents()
print(items)
4. Scroll or click if needed
For infinite scroll or “Load more” buttons:
- Scroll the page to trigger loading
- Click buttons repeatedly
- Wait for new content each time
Important considerations
- Check the site’s robots.txt and terms of service
- Avoid aggressive scraping
- Add delays and rate limiting
- Use headers / sessions if needed
- Be mindful of logins, CAPTCHAs, and anti-bot protection
Best practice
- First inspect whether the data comes from an API.
- If not, use Playwright/Selenium.
- Parse the rendered DOM.
- Add waits and scrolling as needed.
If you want, I can show you:
- a Python Playwright scraper template
- how to find the API behind a JS site
- or how to handle infinite scroll / pagination.