NEWStandard createTask and in.php APIs. Change the address and you are connected.View API docs
GATESOLVER

Web scraping

Scrapy vs Selenium

Scrapy speaks HTTP; Selenium drives a real browser. One is light and fast, the other sees pages exactly as a person does. Most mature scraping projects end up using each where it fits, and this article shows how to decide.

Two different machines

Scrapy sends HTTP requests and receives HTML or JSON. It never runs the page's JavaScript, never loads images or fonts unless you ask, and never lays anything out on a screen. That is why it can keep many requests in flight from one process with modest memory.

Selenium automates a real browser: Chrome, Firefox, Edge or Safari. Every page load runs scripts, fetches stylesheets and images, builds the DOM and renders it, exactly as for a person. That makes Selenium the tool that sees what users see, including content that only exists after JavaScript runs, and it lets you click, type and scroll. The price is resources: each browser instance needs far more memory and CPU than an HTTP request, and pages take longer to finish.

The cost of a page

Think about what one page view costs in each tool. With Scrapy, a page is one request and one response, typically some tens or hundreds of kilobytes of HTML. With Selenium, the same page might trigger dozens of requests for scripts, styles, images, fonts and tracking calls, plus the CPU time to execute and render them. Exact numbers vary widely by site, so measure your own target, but the direction never changes: a browser does far more work per page.

That difference shows up in three places:

  • Throughput. A single Scrapy process can keep many requests in flight. A machine running browsers is limited by how many instances fit in memory.
  • Infrastructure. Browser fleets need more servers, or a grid such as Selenium Grid, and more care to keep stable.
  • Bandwidth. If you pay per gigabyte for proxies, every image and script a browser downloads adds to the bill. Blocking unneeded resources helps but rarely brings a browser down to HTTP levels.

Side by side

ScrapySelenium
Runs page JavaScriptNoYes
Resource use per pageLowHigh
ConcurrencyBuilt in, many requests per processOne page per browser tab or instance
Interaction (click, type, scroll)No, only requestsYes
Crawling featuresScheduler, dedup, retries, exportsNone, you build them
Looks like a real browserOnly at the HTTP levelYes, with caveats (automation flags)
LanguagesPythonPython, Java, C#, JavaScript, Ruby and more

Which sites need a browser

Less often than people assume. Many sites that look dynamic load their data from a JSON API, and you can call that API directly with Scrapy. Open the Network panel, filter by Fetch/XHR, reload, and look for responses that contain your data. If you find them, you have a fast, stable source that does not depend on HTML layout at all; see hidden API scraping.

A browser is genuinely needed when:

  • the data is computed in the page by JavaScript and never sent as clean JSON;
  • requests are signed by scripts in a way that is impractical to reproduce;
  • the flow requires interaction that triggers server state, such as multi step forms;
  • a bot check runs JavaScript in the page and only a real browser passes it reliably.

Our note on how to scrape JavaScript heavy sites lists more signs.

Writing the same scraper both ways

Scrapy, calling the JSON endpoint

import scrapy

class OffersApiSpider(scrapy.Spider):
    name = "offers_api"
    start_urls = [f"https://shop.example.org/api/offers?page={n}" for n in range(1, 6)]
    custom_settings = {"DEFAULT_REQUEST_HEADERS": {"Accept": "application/json"}}

    def parse(self, res):
        for offer in res.json()["items"]:
            yield {"sku": offer["sku"], "price": offer["price"]["amount"]}

Selenium, reading the rendered page

from selenium.webdriver import Chrome, ChromeOptions
from selenium.webdriver.common import by
from selenium.webdriver.support import expected_conditions as cond, ui

browser_opts = ChromeOptions()
browser_opts.add_argument("--headless=new")
chrome = Chrome(options=browser_opts)
try:
    chrome.get("https://shop.example.org/offers")
    ui.WebDriverWait(chrome, 15).until(cond.presence_of_all_elements_located((by.By.CSS_SELECTOR, "[data-sku]")))
    offers = [(el.get_attribute("data-sku"), el.find_element(by.By.CSS_SELECTOR, ".amount").text)
              for el in chrome.find_elements(by.By.CSS_SELECTOR, "[data-sku]")]
finally:
    chrome.quit()

The Selenium version is just as short, but each run starts a browser, loads the full page with all its assets, and waits for rendering. For five pages that hardly matters; for fifty thousand it decides your infrastructure budget.

Hybrid setups

The most effective pattern for difficult sites is to use a browser only where it adds something, and plain HTTP for everything else.

Browser for the session, Scrapy for the pages

Open the site once in Selenium, complete whatever check or login the site requires, then copy the cookies into Scrapy requests. Selenium's driver.get_cookies() returns a list of dictionaries you can turn into a cookies argument on scrapy.Request. Keep the same User-Agent in both, and the same IP if the site ties sessions to addresses. When the cookies expire, refresh them with another browser visit.

Browser rendering inside Scrapy

Plugins let Scrapy send selected requests through a real browser while keeping its scheduler, retries and pipelines. The maintained option at the time of writing is scrapy-playwright, which uses Playwright rather than Selenium; you mark individual requests with meta={"playwright": True} and the rest stay plain HTTP. Older Selenium based middlewares exist, but check their maintenance status before depending on them. The Scrapy with Playwright guide walks through the setup.

Listing pages by HTTP, detail pages by browser

Often the list of items is plain HTML while the detail pages need JavaScript, or the reverse. Split the crawl accordingly: Scrapy discovers URLs quickly, and a small browser pool handles only the pages that need it.

Bot checks and CAPTCHAs

A common reason teams move from Scrapy to Selenium is a bot check. Sometimes that helps, because the browser runs the check's JavaScript. But automated browsers have their own tells, such as the navigator.webdriver flag, and many checks still end in a CAPTCHA. Two things are worth knowing:

  • Token CAPTCHAs such as reCAPTCHA and Turnstile can be solved through an API from either tool. The API returns a token; in Scrapy you post it with the form, in Selenium you place it in the page. Neither tool has to "see" the puzzle.
  • Firewall checks such as AWS WAF or the Cloudflare challenge end in a cookie. Once you have the cookie, plain HTTP clients can usually continue, which brings you back to Scrapy's cost profile.

So a browser is not automatically the answer to a CAPTCHA. Often the cheaper design is Scrapy plus a middleware that solves the challenge when it appears; see handling CAPTCHAs in a Scrapy middleware and the Selenium integration for the browser side.

Making the call

Default to Scrapy, or to plain HTTP in general. Move a page to a browser when you have evidence that HTTP cannot get the data: the JSON is not available, the requests are signed, or the check only passes in a real browser. Keep the browser part as small as possible, and measure the cost per page of each path so the decision stays grounded in numbers from your own project.

Whatever the stack, the same rules keep a crawl healthy: modest concurrency per site, realistic pacing, public data only, and a quick stop when a site signals it is under strain.

Common questions

Is Selenium slower than Scrapy?

Per page, yes. A browser loads and runs every script, style and image, while Scrapy fetches only the document, so Scrapy handles far more pages with the same hardware.

Can Scrapy run JavaScript?

Not by itself. Plugins such as scrapy-playwright send chosen requests through a real browser while the rest stay plain HTTP.

Do I need Selenium to solve CAPTCHAs?

No. Token CAPTCHAs can be solved through an API and posted from Scrapy, and firewall checks return cookies that HTTP clients can reuse.

Can I pass Selenium cookies to Scrapy?

Yes. Read them with get_cookies, pass them as the cookies argument of scrapy.Request, and keep the same User-Agent and IP.

Which should a beginner learn first?

Learn HTTP scraping first, with requests or Scrapy. It teaches how sites really deliver data, which also makes browser automation easier later.

Keep reading