Category:Scraping BasicsView as Markdown
Scrape JavaScript Websites with Python: 6 Methods Tested

Founder @ Scrape.do
A JavaScript-rendered page sends your scraper an HTML shell and fills it in later, inside the browser. Python can still get the data in two ways: call the JSON endpoint the page itself calls, or run a browser (your own or a hosted one) and wait for the data to appear before you read the HTML.
This guide runs six methods against the same demo page, from a plain requests call to Playwright, Selenium, nodriver, Scrapy and the Scrape.do API. Every script below was run against the live demo pages, and every output block is copied from those runs.
| Method | Use it when | Speed (one page) | Setup | Blocks |
|---|---|---|---|---|
| Hidden JSON API + requests | The page loads its data from an XHR or fetch call you can repeat | Fastest, about 5x faster than Playwright | pip install requests |
No browser at all, so a JavaScript challenge or a token the page computes stops it |
| Playwright | You need a real browser and want the cleanest waiting API | Fastest browser method | pip + a browser download | Headless mode sends HeadlessChrome in the user agent and sets navigator.webdriver to true |
| Selenium 4 | You already have Selenium code or need its ecosystem | Close to Playwright | pip; Selenium Manager fetches the driver | Same as Playwright: HeadlessChrome and navigator.webdriver is true |
| nodriver | You want async Chrome without WebDriver | Slower than Playwright | pip + your installed Chrome | navigator.webdriver is false, but headless mode still sends HeadlessChrome. AGPL license |
| Scrapy + scrapy-playwright | Crawling many pages, where only some need a browser | Slower than Playwright for one page; loads many pages at once | pip + the Playwright browser | Same browser as Playwright |
Scrape.do API (render=true) |
You don't want to run browsers, or the site blocks you | Slowest for one page, with no browser to run yourself | pip install requests + a token |
The target saw a regular Chrome user agent; proxies and anti-bot handling run on the API side |
Speed compares a fresh python script.py run on the same machine, browser start included. Your machine and network set the absolute numbers. The demo pages aren't protected, so the last column lists what each method exposes, not a block rate.
Why Does requests Return an Empty Page on JavaScript Sites?
A plain HTTP client downloads the HTML the server sends and stops there. On a server-rendered page, that HTML already holds the data. On a JavaScript-rendered page it holds a template, a few <script> tags and empty containers.
What Is the Difference Between Static and JavaScript-Rendered Pages?
- Static or server-rendered pages: the response contains the text you see.
requestsplus BeautifulSoup is enough. - JavaScript-rendered pages: the response contains the layout. JavaScript then calls an API, receives JSON and writes it into the page. React, Vue and Angular apps work this way, and so do plenty of older jQuery pages.
How Do You Know if a Page Needs JavaScript?
Three quick checks tell you which kind of page you have before you write any code:
- View the source. Press Ctrl+U (Cmd+Option+U on a Mac) and search for a value you can see on the page, like a price or a name. If it isn't in the source, JavaScript adds it.
- Turn JavaScript off. In Chrome DevTools, open the Command Menu (Ctrl+Shift+P), run "Disable JavaScript" and reload. An empty table or a spinner means the content depends on JavaScript.
- Ask Python. Fetch the page with
requestsand searchresponse.textfor the same value. The next sections do exactly this.
How Long Should You Wait for a JavaScript Page to Load?
The demo page used here, the AJAX and JavaScript sandbox on Scrape This Site, lists Oscar-winning films by year.

Its own script shows the whole sequence:
- The server sends the page with an empty
<tbody id="table-body">. - jQuery reads the year from the URL hash (
#2015) and sendsGET /pages/ajax-javascript/?ajax=true&year=2015. - The response is JSON, one object per film.
- The script waits another 1.5 seconds on purpose (
setTimeout(..., 1500), commented "add intentional delay to emphasize async UI") and only then writes the rows into the table.
That last step matters more than it looks. Here is when each wait option hands the page back in headless Chrome:

The rows arrive well after DOMContentLoaded, and neither page event tracks them: load can fire before the rows, or long after them when slow analytics scripts hold it up. A scraper that reads the HTML at the wrong moment gets an empty table, and that is how the old snippets failed.
What Happens When You Scrape It with requests?
You need a recent Python 3: version 3.11 or newer installs the current release of every library here. Work in a virtual environment. New to scraping in Python? Start with web scraping with Python, then come back here for the JavaScript part.
python -m venv .venv
source .venv/bin/activate
pip install requests beautifulsoup4
Here is the plain request:
import requests
from bs4 import BeautifulSoup
url = "https://www.scrapethissite.com/pages/ajax-javascript/#2015"
response = requests.get(url, timeout=30)
soup = BeautifulSoup(response.text, "html.parser")
rows = soup.select("#table-body tr")
print(f"Status: {response.status_code}, film rows in the HTML: {len(rows)}")
print(soup.select_one("#table-body"))
The server answers with a 200 and no data:
Status: 200, film rows in the HTML: 0
<tbody id="table-body">
</tbody>
The #2015 part never reaches the server either: HTTP clients don't send the URL fragment, so the request asks for the bare page.
How Do I Find a Site's Hidden API and Call It from Python?
Before you start a browser, find out where the data comes from. Open the page in Chrome, open DevTools (F12), go to the Network tab, filter by Fetch/XHR and reload. On this page one request stands out: ?ajax=true&year=2015, and its Response tab shows the film list as JSON.
Repeat that request from Python:
import requests
url = "https://www.scrapethissite.com/pages/ajax-javascript/"
response = requests.get(url, params={"ajax": "true", "year": 2015}, timeout=30)
response.raise_for_status()
films = response.json()
for film in films:
print(film["title"].strip(), film["nominations"], film["awards"], film.get("best_picture", False))
print(f"{len(films)} films")
Output (first 5 of 16 rows):
Spotlight 6 2 True
Mad Max: Fury Road 10 6 False
The Revenant 12 3 False
Bridge of Spies 6 1 False
The Big Short 5 1 False
...
16 films
You get typed fields (awards is already an integer, best_picture is a boolean) and none of the page's 1.5-second delay. It was the fastest method on both demo pages.
Not every page makes it this easy:
- The data may be embedded instead of fetched. On quotes.toscrape.com/js there is no XHR at all: the ten quotes sit in a
var data = [...]array inside a<script>tag. A regex around that array plusjson.loadsgets them in one request. Next.js sites on the Pages Router do the same with a<script id="__NEXT_DATA__">block. - The endpoint may need things the page builds in JavaScript: a signed token, a GraphQL query hash, cookies from a challenge. Those rotate, so copy them from the browser once to test, then look up where the page gets them.
- Anti-bot systems protect APIs too. A JSON endpoint behind a bot-protection layer refuses a bare
requestscall the same way the HTML page does.
When the endpoint is out of reach, run a browser.
How Do You Scrape a JavaScript Website with Playwright?
Playwright drives Chromium, Firefox and WebKit from one API, and its waiting methods are the easiest to get right. Install it and its browser:
pip install playwright
playwright install chromium
from playwright.sync_api import sync_playwright
URL = "https://www.scrapethissite.com/pages/ajax-javascript/#2015"
with sync_playwright() as p:
browser = p.chromium.launch(headless=True)
page = browser.new_page()
page.goto(URL, wait_until="domcontentloaded") # don't wait for every tracker script
page.wait_for_selector("tr.film") # wait until the JavaScript has filled the table
films = []
for row in page.locator("tr.film").all():
films.append({
"title": row.locator(".film-title").inner_text().strip(),
"nominations": int(row.locator(".film-nominations").inner_text()),
"awards": int(row.locator(".film-awards").inner_text()),
})
browser.close()
for film in films:
print(film)
print(f"{len(films)} films")
{'title': 'Spotlight', 'nominations': 6, 'awards': 2}
{'title': 'Mad Max: Fury Road', 'nominations': 10, 'awards': 6}
{'title': 'The Revenant', 'nominations': 12, 'awards': 3}
...
16 films
Two choices in that script are deliberate:
- Wait for the element, not for the network. The old version of this post used
wait_until="networkidle". Playwright's own API docs mark that option as DISCOURAGED, and on this page it is a race: the network can go quiet while the 1.5-second timer is still running. In testing, the old snippet sometimes returned an empty table and once timed out. - Don't wait for
loadeither.goto()waits for theloadevent by default. That event tracks the page's own files, not the XHR, so on this page it can fire before the rows exist, or much later when slow analytics scripts hold it up.
For a deeper tour (screenshots, request interception, stealth), see the Playwright web scraping guide and the Python headless browser comparison.
How Do You Scrape JavaScript Pages with Selenium?
Selenium is still everywhere, and Selenium 4 removed most of its old setup pain. Since version 4.6 it ships with Selenium Manager, which finds your installed Chrome and downloads the matching driver on first use. You no longer need webdriver-manager or a chromedriver on your PATH.
pip install selenium
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
URL = "https://www.scrapethissite.com/pages/ajax-javascript/#2015"
options = webdriver.ChromeOptions()
options.add_argument("--headless=new")
options.page_load_strategy = "eager" # return at DOMContentLoaded, not after every tracker
driver = webdriver.Chrome(options=options) # Selenium Manager finds or downloads the driver
try:
driver.get(URL)
WebDriverWait(driver, 15).until(EC.presence_of_element_located((By.CSS_SELECTOR, "tr.film")))
films = []
for row in driver.find_elements(By.CSS_SELECTOR, "tr.film"):
title, nominations, awards, _ = [td.text for td in row.find_elements(By.TAG_NAME, "td")]
films.append({"title": title.strip(), "nominations": int(nominations), "awards": int(awards)})
finally:
driver.quit()
for film in films:
print(film)
print(f"{len(films)} films")
{'title': 'Spotlight', 'nominations': 6, 'awards': 2}
{'title': 'Mad Max: Fury Road', 'nominations': 10, 'awards': 6}
...
16 films
The very first run is slow, because Selenium Manager downloads the driver. Runs after that use the cached copy.
If you are updating an older Selenium script, check two lines:
options.headless = Truedoes nothing any more. Selenium deprecated the property in 4.8 and removed it in 4.13. The assignment raises no error, and Chrome opens a visible window. Useoptions.add_argument("--headless=new").implicitly_wait()does not wait for content. It only changes how longfind_elementretries.driver.page_sourceright afterget()returns whatever is there at that moment. The old version of this post did exactly that, and whether the rows were there depended on timing.WebDriverWaiton the element you need fixes it.
More patterns (clicks, scrolling, logins) are in the Selenium web scraping tutorial.
What Is nodriver, and Can It Replace Pyppeteer?
The old version recommended Pyppeteer here. Its README now opens with "This repo is unmaintained" and points to Playwright. If you want what Pyppeteer offered, an async library that talks to Chrome over the DevTools Protocol, the maintained option is nodriver. It comes from the author of undetected-chromedriver, describes itself as that package's official successor, and needs no chromedriver binary and no Selenium.
pip install nodriver
import nodriver as uc
URL = "https://www.scrapethissite.com/pages/ajax-javascript/#2015"
async def main():
browser = await uc.start(headless=True)
tab = await browser.get(URL)
await tab.select("tr.film", timeout=15) # waits for the first row to appear
films = []
for row in await tab.select_all("tr.film"):
title, nominations, awards, _ = [cell.text.strip() for cell in row.children]
films.append({"title": title, "nominations": int(nominations), "awards": int(awards)})
browser.stop()
for film in films:
print(film)
print(f"{len(films)} films")
uc.loop().run_until_complete(main())
{'title': 'Spotlight', 'nominations': 6, 'awards': 2}
...
16 films
What to weigh before you pick it:
- It drives the Chrome you already have installed, so there is no separate browser download.
- In headless mode it reports
navigator.webdriverasfalse, where Playwright and Selenium reporttrue. The user agent still saysHeadlessChrome, so it is not invisible. - Its documentation is thinner than Playwright's, and the project is younger, still on 0.x versions.
- It is licensed under the AGPL-3.0. Check what that means for your project before you build a product on it. Playwright and Selenium are Apache-2.0.
Can Scrapy Scrape JavaScript Pages?
The old version paired Scrapy with Splash. Splash's last release, 3.5, dates from 2020, it needs its own Docker service, and it renders with QtWebKit. Its own FAQ lists WebKit compatibility issues as a reason pages fail to render. scrapy-playwright replaces it: a Scrapy download handler that sends the requests you mark to a real Playwright browser and everything else through Scrapy's normal downloader.
pip install scrapy scrapy-playwright
playwright install chromium
import scrapy
from scrapy_playwright.page import PageMethod
HANDLER = "scrapy_playwright.handler.ScrapyPlaywrightDownloadHandler"
class FilmsSpider(scrapy.Spider):
name = "films"
custom_settings = {
"DOWNLOAD_HANDLERS": {"http": HANDLER, "https": HANDLER},
"TWISTED_REACTOR": "twisted.internet.asyncioreactor.AsyncioSelectorReactor",
}
async def start(self):
meta = {"playwright": True, "playwright_page_goto_kwargs": {"wait_until": "domcontentloaded"},
"playwright_page_methods": [PageMethod("wait_for_selector", "tr.film")]}
for year in [2015, 2014, 2013]:
url = f"https://www.scrapethissite.com/pages/ajax-javascript/#{year}"
yield scrapy.Request(url, meta=meta, cb_kwargs={"year": year}, dont_filter=True)
def parse(self, response, year):
for row in response.css("tr.film"):
yield {"year": year,
"title": row.css(".film-title::text").get("").strip(),
"nominations": int(row.css(".film-nominations::text").get()),
"awards": int(row.css(".film-awards::text").get())}
Run it without a project:
scrapy runspider films_spider.py -o films.json
It returned every film for the three years, the same rows as the JSON endpoint, and Scrapy loads the three pages concurrently.
dont_filter=True is not optional here. Scrapy's duplicate filter ignores the #fragment when it fingerprints a URL, so the three year URLs look identical to it. Without the flag, Scrapy drops two of the three requests and returns only one year's films.
Pick this when the job is a crawl: many URLs, retries, throttling, pipelines and exports, with a browser only for the pages that need one. The Scrapy tutorial covers the crawling side.
How Do You Scrape JavaScript Pages Without Running a Browser?
Every browser method above runs Chrome on your machine. That is fine for small jobs. It gets expensive in memory, in IP reputation and in maintenance once you scale up or the site starts blocking you. A web scraping API runs the browser for you and returns the rendered HTML to a plain HTTP call.
With Scrape.do you add render=true to the request, and a wait parameter that matches the page. Plain requests and BeautifulSoup are all you need:
import requests
from bs4 import BeautifulSoup
params = {
"token": "<your_token>",
"url": "https://www.scrapethissite.com/pages/ajax-javascript/#2015",
"render": "true", # load the page in a headless browser
"waitSelector": "tr.film", # return once the first row exists (up to 10 seconds)
}
response = requests.get("https://api.scrape.do/", params=params, timeout=90)
response.raise_for_status()
print("Credits used:", response.headers.get("Scrape.do-Request-Cost"))
films = []
for row in BeautifulSoup(response.text, "html.parser").select("tr.film"):
title, nominations, awards, _ = [td.get_text(strip=True) for td in row.select("td")]
films.append({"title": title, "nominations": int(nominations), "awards": int(awards)})
if not films:
raise SystemExit("No rows: the selector did not match. Check the HTML and retry.")
for film in films:
print(film)
print(f"{len(films)} films")
Credits used: 5
{'title': 'Spotlight', 'nominations': 6, 'awards': 2}
...
16 films
The wait parameter decides whether you get data:
| Parameters | Result on the demo page |
|---|---|
render=true only (waits for domcontentloaded by default) |
Empty table: the HTML comes back before the rows exist |
render=true&waitSelector=tr.film |
All rows, returned as soon as they exist |
waitSelector waits a limited time for the element and then returns whatever the page has, so keep the empty-result check in your code. For pages without a reliable selector, customWait adds a fixed pause, and waitUntil sets which page event to wait for (wait parameters).
Add returnJSON=true and the API also lists the XHR and fetch calls the page made, with their response bodies. That is a shortcut back to the hidden API method: it finds the endpoint without DevTools.
import requests
params = {
"token": "<your_token>",
"url": "https://www.scrapethissite.com/pages/ajax-javascript/#2015",
"render": "true",
"waitSelector": "tr.film",
"returnJSON": "true", # also return the XHR and fetch calls the page made
}
data = requests.get("https://api.scrape.do/", params=params, timeout=90).json()
for call in data["networkRequests"]:
print(call["method"], call["status"], call["url"])
print(call["response_body"][:120])
GET 200 https://www.scrapethissite.com/pages/ajax-javascript/?ajax=true&year=2015
[
{
"title": "Spotlight ",
"year": 2015,
"awards": 2,
"nominations": 6,
"best_picture": true
},
POST 204 https://www.scrapethissite.com/cdn-cgi/rum?
Rendered requests cost more credits than plain ones, and only successful responses are billed (request costs).
What Replaced requests-html, Pyppeteer and Splash?
| Old method | Status | What the re-runs showed | Replaced by |
|---|---|---|---|
| Requests-HTML | No release since 2019 | ImportError on current lxml until you add lxml_html_clean. Then render(wait=2) usually returned an empty table, because wait is a pause before loading the page. render(sleep=3), the pause after, returned all rows |
Hidden JSON API, or Playwright |
| Pyppeteer | README: "This repo is unmaintained". No release since 2024 | Pins urllib3<2, an old major version with known advisories, and downloads its own Chromium snapshot on first run. Pointed at a current Chrome, the old snippet still returned all rows: the reason to move is maintenance, not the result |
nodriver |
| Scrapy + Splash | No Splash release since 2020; needs its own Docker service | Not run: it needs a Docker service, and it renders with QtWebKit, not Chromium | Scrapy + scrapy-playwright |
| Every old snippet | Printed html[:500], which is the page's <head>, so none of them showed whether the table had loaded |
Code that parses and counts the rows |
Which Method Is Fastest for JavaScript Pages?
Every method ran in a fresh process against two demo pages: the films page and quotes.toscrape.com/js. A run counted as a success only when the parsed rows matched the site's own data: all 16 films, or all 10 quotes.
| Method | Gets the data | How it waits | Speed (one page) |
|---|---|---|---|
| requests only (control) | No: empty table | It doesn't: no JavaScript runs | Fast, but returns nothing |
| Hidden JSON API | Yes, on both pages (from the <script> tag on the quotes page) |
Nothing to wait for: it reads the data directly | Fastest, about 5x faster than Playwright |
| Playwright | Yes, on both pages | wait_for_selector on the rows |
Fastest browser method |
| Selenium 4 | Yes, on both pages | WebDriverWait on the rows |
Close to Playwright |
| nodriver | Yes, on both pages | tab.select on the rows |
Slower than Playwright |
| Scrapy + scrapy-playwright | Yes, on both pages | PageMethod("wait_for_selector", ...) |
Slower than Playwright for one page; loads many pages at once |
Scrape.do render=true + waitSelector |
Yes, on the films page | waitSelector=tr.film |
Slowest for one page, with no browser to run yourself |
On the films page, every rendered Scrape.do request with waitSelector returned the full table. Whichever tool fetched the page, check for an empty result before you trust it.
The old snippets, run as published (Pyppeteer and requests-html pointed at a current Chrome, Selenium with --headless=new added so the test didn't open windows):
| Old snippet | Result |
|---|---|
Requests-HTML, render(wait=2) |
Usually an empty table: wait pauses before the page loads |
Selenium, implicitly_wait(5) |
Depends on timing: sometimes an empty table |
Playwright, wait_until="networkidle" |
Depends on timing: sometimes an empty table, once a timeout |
Pyppeteer, waitUntil="networkidle0" |
Returned the rows, but the library is unmaintained |
The Selenium and Playwright snippets returned the rows every time on a slower, busier machine and missed them on a faster one. When the result depends on how fast the machine is, the wait is a race, which is why every script above waits for the rows themselves.
How Should You Scrape a JavaScript Website with Python?
- Check DevTools first. If the data arrives as JSON, call that endpoint with
requests. It is the fastest method here, about 5x faster than Playwright on the films page, and it doesn't care how the page is drawn. - For a browser on small jobs, use Playwright, and wait for the element you need, never for
networkidle. - If you already have Selenium code, keep it and move it to
--headless=new, Selenium Manager andWebDriverWait. - For async scripts on the Chrome you already have, nodriver works, if the AGPL license fits your project.
- For crawls of thousands of URLs, use Scrapy, with scrapy-playwright only on the requests that need rendering.
- If the output feeds an LLM, Crawl4AI drives Chromium through Playwright and hands you the page as Markdown.
- If you are blocked, or don't want to run browsers at all, send the page to a rendering API such as Scrape.do with
render=trueandwaitSelector.
For the wider toolbox, see the list of Python web scraping libraries. If a site starts answering with challenge pages instead of HTML, the Cloudflare guide covers what each approach does against them.
FAQ
Can BeautifulSoup Scrape JavaScript-Rendered Pages?
No. BeautifulSoup parses the HTML you give it and never runs JavaScript. Feed it the JSON endpoint's data, or HTML that a browser (Playwright, Selenium, nodriver) or a rendering API has already rendered.
Is Playwright or Selenium Better for JavaScript Pages?
For new scrapers, usually yes: auto-waiting locators, one install command for the browser, and a single API for Chromium, Firefox and WebKit. Selenium 4 closed much of the gap with Selenium Manager, and it is the better pick when you already have Selenium code or need its grid.
Should I Scrape JavaScript Sites with Python or Node.js?
Both work, and the browser does the same job either way: Playwright and Puppeteer started in Node.js, and Playwright has an official Python version. Pick the language your pipeline already uses. The Python vs Node.js comparison goes through speed, libraries and deployment side by side.
Is requests-html Still Maintained?
No. Its last release was in February 2019, it fails to import on current lxml without an extra package, and it renders through Pyppeteer, which is unmaintained too.

Founder @ Scrape.do

