Mixing rendered and plain requests in one crawl

One login page, fifty thousand product pages

Picture a crawl of a trade supplier’s catalogue. You log in through a form that runs a pile of JavaScript and sets a session cookie. The category pages are a single-page app shell that builds its product grid from script. And the fifty thousand product detail pages behind that grid are plain server-rendered HTML that any HTTP client can fetch and parse in milliseconds, as long as the request carries the session cookie.

Run the whole thing in a browser and you pay browser prices for fifty thousand pages that never needed one. Run it all through an HTTP client and you can’t log in or see the grid. The obvious answer is both, in one job: render the login and the category shells, fetch the product pages plainly, and share the session between them.

Earlier guides in this series make the case for that in a sentence or two, and they’re right. The headless-versus-HTTP piece and the Playwright-versus-Scrapy piece both land on “crawl wide and cheap, render narrow and expensive.” What neither covers is how to actually build it, and the building is where it gets awkward. Two fetchers means two concurrency models, two failure profiles, a session that has to cross from one to the other, and a routing decision on every URL.

This article is that build. It covers deciding which pages go to which lane, the three common ways to wire the lanes together in Python, handing cookies and other session state from the browser to the client, what to do when a session is tied to more than cookies, keeping each lane’s concurrency separate, refreshing an expired login without every worker stampeding the login page, and monitoring the mix so the expensive lane doesn’t quietly grow.

We run mixed crawls like this in production, and the pattern holds across most sites where the browser is needed for a small part of the job. None of the figures here are benchmarks. The shape of the design is what transfers from one target to the next.

Why either-or is the wrong framing

The browser-versus-HTTP decision gets framed per site: this target needs Playwright, that one doesn’t. That framing is a leftover from tooling that made mixing awkward. The honest unit of decision is the page type, not the site.

Within one site, page types differ enormously. A login flow might need a browser for its JavaScript. A search results page might be client-rendered. A detail page might be server-rendered. A sitemap is plain XML. An internal JSON endpoint behind the listing grid needs no rendering at all. Treating the whole site as “needs a browser” because one page type does means every other type pays for it.

The cost gap is large, and it compounds. A browser render pulls every asset the page references unless you filter it, runs the page’s scripts, holds memory for the whole context, and ties up a slot in a pool that’s always smaller than your HTTP concurrency. An HTTP fetch pulls one document. On a crawl where the browser is only needed for a small share of pages, a mixed design spends browser time only on that share.

There’s also a reliability argument that gets less attention. Browsers fail in more ways than HTTP clients: navigation timeouts, pages that never reach network idle, crashed contexts, memory leaks over long runs. Every page you move out of the browser is a page that can’t fail in those ways.

The cost of mixing is complexity, and it’s real. You maintain two fetch paths, you move state between them, and you debug problems that exist only at the boundary. The rest of this piece is about keeping that complexity contained, so the saving doesn’t get eaten by the maintenance.

Which pages actually need the browser

Before designing lanes, sort the target’s page types by whether each genuinely needs rendering. The test is the same one the headless-versus-HTTP guide describes, applied per type rather than per site: fetch a sample of that page type with a plain client, parse it, and see whether the fields you need are there.

A few categories usually land in the browser lane.

Login and account flows that build their form with script, compute a value in the browser before submitting, or set their session through JavaScript rather than a plain Set-Cookie header. Many login forms are plain HTML posts, which an HTTP client can submit directly, so check before assuming.

Client-rendered shells, where the raw HTML is a near-empty container and the content arrives through script. Before routing these to the browser, look for the API the shell calls. If you can call it directly, the page type moves to the HTTP lane as a JSON fetch.

Pages that require an interaction to reveal data, such as a click to expand, a variant selector, or a scroll that loads more. Sometimes the interaction just triggers a request you can replicate. Sometimes it depends on page state you can’t easily rebuild.

State setup steps, like choosing a region or currency, accepting a consent banner that gates content, or starting a session that the site initialises through script.

Everything else goes in the HTTP lane by default: server-rendered detail pages, sitemaps and feeds, JSON endpoints, and any image or document URL, plus listings that paginate through query strings.

Write the result down as a table of page type, lane and reason. It becomes the routing config, and the reason column is what lets the next person challenge a decision instead of inheriting it.

The shape of a hybrid crawl

The design that holds up has one frontier and two fetch lanes, with a shared session and a single parsing layer.

One frontier means a single queue of URLs to fetch, with each URL tagged by page type. Keeping a single frontier matters because deduplication, priorities and crawl scope should apply across both lanes. Two separate queues drift: a URL discovered by the browser lane gets fetched again by the HTTP lane, or a scope rule gets updated in one and not the other.

Two lanes means two fetchers with separate concurrency limits. The browser lane has a small pool of contexts and pages. The HTTP lane has a larger connection pool. Each lane pulls only the URLs routed to it.

One shared session means the cookies and any other session state established in one lane are available to the other. In most mixed crawls the flow is browser to HTTP: the browser logs in or sets up state, and the HTTP lane reuses that state for the bulk fetches. Occasionally it runs the other way, where the HTTP lane has a valid session and a browser page needs it.

One parsing layer means extractors don’t care which lane fetched a page. A detail page parses the same way whether it came from the browser or the client, which keeps extraction testable against saved pages and lets you move a page type between lanes without touching its parser. If the browser lane serialises the page after rendering, make sure that serialisation includes what the parser needs, remembering that shadow roots and frames don’t survive a plain page.content().

A router sits between the frontier and the lanes, reading each URL’s page type and applying the routing table. That router is the one piece of code that knows about both lanes, and keeping it small is the best defence against the design spreading.

scrapy-playwright: rendering as a per-request option

If you’re already on Scrapy, scrapy-playwright is the most direct way to build this. It replaces Scrapy’s download handler for HTTP and HTTPS with one that can render through Playwright, and it requires Scrapy’s asyncio-based Twisted reactor, which you set in the project settings.

The key design choice in the plugin is that rendering is opt-in per request. A request with playwright set to true in its meta goes through the browser. A request without it goes through Scrapy’s normal downloader, exactly as before. That maps directly onto the two-lane model: the router is whatever code sets that meta key, usually in the spider’s callbacks or a small helper that looks up the page type.

The plugin exposes the pieces you need for the browser lane. playwright_page_methods lets you run actions like waiting for a selector or clicking before the response is returned. playwright_include_page hands the live page object to your callback when you need to interact further, with the obligation to close it yourself. Named contexts through playwright_context let you keep separate browser sessions, and settings like PLAYWRIGHT_MAX_CONTEXTS and PLAYWRIGHT_MAX_PAGES_PER_CONTEXT cap the browser lane’s footprint independently of Scrapy’s CONCURRENT_REQUESTS.

Session sharing is the part to verify rather than assume. Scrapy has its own cookie middleware and jar, the browser context has its own cookie store, and how headers and cookies flow between them depends on the plugin’s request-header handling settings and on which lane set the cookie. On a target where the browser logs in and plain requests need that session, test the handoff explicitly: log in through the browser lane, issue one plain request, and confirm it comes back authenticated. If it doesn’t, read the cookies out of the browser context in your callback and attach them to the follow-up requests yourself.

The advantage of this route is that everything else Scrapy gives you, from scheduling and deduplication to pipelines and throttling, applies to both lanes automatically.

Crawlee and the adaptive approach

Crawlee takes a different angle. It ships separate crawler classes for HTTP fetching with a parser and for browser fetching with Playwright, which share the same request queue, storage and session pool abstractions. You can run both crawler types against one request queue, routing by label, which gives you the two-lane design with the frontier shared.

Recent versions of Crawlee also include an adaptive crawler that tries to decide per page whether a plain HTTP fetch is enough, by rendering some pages and comparing what a static fetch would have produced. The idea is that it learns which page types need a browser so you can skip classifying them by hand. The idea appeals, and it’s worth trying on targets with many page types. Check its decisions against your own sample before trusting it on a large crawl, because a wrong “static is enough” call shows up as empty fields rather than as an error.

Crawlee’s session pool is also relevant here. It groups cookies and proxy assignment into sessions and retires sessions that start failing, which is exactly the unit a mixed crawl needs to share between lanes. How cleanly that sharing works across crawler types depends on the version and language, Python or JavaScript, so treat it like the Scrapy handoff: test that a session established in the browser lane actually authenticates in the HTTP lane before building on it.

The trade-off against Scrapy is ecosystem. Scrapy’s middleware and extension ecosystem is older and larger. Crawlee’s browser integration is more native, since it was designed around browsers from the start. If you’re choosing a framework for a job that’s mostly mixed crawling, that difference matters more than any speed comparison. The Crawlee-versus-Scrapy guide in this series goes deeper on the frameworks themselves.

Plain Python: Playwright plus an HTTP client

Plenty of mixed crawls don’t need a framework. A Playwright script for the browser lane, httpx or requests for the HTTP lane, and a queue between them is often the clearest design, especially when the browser part is a single login or setup step.

The minimal version runs the browser once. Launch a context, log in, set any state the site needs, then read the session out with context.cookies() or save the whole thing with context.storage_state(), which captures cookies and local storage for each origin. Close the browser. Build an HTTP client with those cookies loaded, and run the bulk crawl with ordinary async requests.

Playwright also has a middle option that’s easy to miss. Every browser context has an associated APIRequestContext, reached as context.request, which makes plain HTTP requests without rendering and shares the context’s cookie storage. Cookies set by the browser are sent with those requests, and cookies set by their responses update the context. For a small number of plain requests alongside a browser session, it’s the simplest possible handoff, because there isn’t one: both use the same store.

It isn’t a replacement for a real HTTP lane at volume. It runs through the Playwright driver, so it doesn’t give you the connection pooling, retry and rate control that a dedicated async client or framework does. But for a crawl where the browser does most of the work and a few JSON endpoints are cheaper called directly, it avoids the whole cookie-copying problem.

For long-running crawls, structure the plain-Python version as two worker pools reading from one queue, one pool of browser workers and one of HTTP workers, with the session held in a shared place both can read and the browser pool can refresh.

Handing the session across

The handoff is where mixed crawls break, and nearly always in the same few ways.

Cookies are the easy part, mostly. context.cookies() returns each cookie with its name and value, its domain and path, its expiry, and its security flags. Load them into your HTTP client’s cookie jar with their domains and paths intact, not as a single flattened Cookie header, so the client sends each cookie only where the browser would have. A flattened header sends every cookie to every host, which leaks session cookies to third-party domains and occasionally breaks requests where two domains use the same cookie name.

Local and session storage don’t transfer as cookies. Single-page apps often keep an access token in local storage and send it in an Authorization header from their own JavaScript. The browser’s cookie store has no idea about it. storage_state() captures local storage, so read the token from there, or watch the browser’s own API requests to see which header carries it, and set the same header in the HTTP client.

CSRF tokens are page-scoped. Forms and some APIs require a token embedded in the page or set in a cookie, which has to be echoed back in a header or field. If the HTTP lane posts anything, it needs to fetch the token the same way the browser did, usually by reading it from a page or cookie before each write.

Headers the site expects have to be consistent. If the browser session was established with one User-Agent and Accept-Language, and the HTTP lane sends different values, some sites treat the session as a different client. Set the HTTP client’s basic headers to match the browser that created the session.

Finally, expiry. Cookies copied at the start of a crawl have the lifetimes they had then. Check the expiry field, and plan for the session ending before the crawl does.

When a session is bound to more than cookies

Some sites tie a session to more than the cookie. The session might be associated with the IP address it was created from, or with characteristics of the client that created it. When the same cookie then arrives from a different IP, or from a client that looks nothing like the one that logged in, the site can treat it as a new or suspicious session and log it out, challenge it, or serve different content.

For a mixed crawl, the IP part has a straightforward answer. Run both lanes for a given session through the same exit IP. With a proxy pool, that means a sticky session: the browser logs in through one exit, and every HTTP request carrying that session’s cookies goes through the same one until the session ends. A rotating pool that assigns a new IP per request breaks this, because the session cookie hops between addresses on every fetch. Most proxy vendors support sticky sessions through a session ID in the proxy username or a dedicated port, and on our own mobile proxy farm we pin each crawl session to one modem for exactly this reason.

The client-characteristics part is different. A browser and an HTTP library look different at several layers, from the TLS handshake to header order to how they handle HTTP/2, and bot-management systems read those layers. Explaining how those systems work is fair game. Giving instructions to disguise an HTTP client as a browser isn’t something this site does, and on a target that enforces client consistency across a session, trying to fake it is the wrong fight anyway.

The honest design choice for those targets is to keep the whole session in the browser lane, or to use a different session for the HTTP lane that’s established by the HTTP client itself, where the site allows it. If neither works, the target has told you how it wants to be accessed, and the mixed design doesn’t apply there.

Deciding the lane for each URL

There are two ways to route: rules decided in advance, or probing and escalating at runtime.

Rules are a lookup from page type to lane, where page type comes from the URL pattern or from the link that discovered the URL. /login and /search go to the browser, /product/ and sitemap URLs go to HTTP. Rules are fast, predictable and easy to test. Their weakness is that they’re only as good as the classification, and a site that changes a page type from server-rendered to client-rendered breaks them silently.

Probe-and-escalate fetches every URL with the HTTP client first, checks whether the result contains the fields expected for that page type, and re-queues the URL for the browser lane if it doesn’t. It adapts automatically when a page type changes. Its weakness is cost: every page that needs a browser gets fetched twice, once cheaply and uselessly, then again in the browser.

The design we run combines them. Rules route each page type by default. A sample of each page type, a few per run, is probed in the other lane and compared. If the HTTP lane starts returning empty fields for a page type that’s routed to it, the comparison catches it and the rule gets revisited. That keeps the steady-state cost of rules with the adaptability of probing, limited to a sample.

One rule for escalation matters more than any other. Escalate on missing content, never on being blocked. If the HTTP lane gets a page shell with no data because the content is client-rendered, the browser is the right tool. If the HTTP lane gets a 403, a 429 or a challenge page, the site is saying no, and answering with a browser is just a more expensive way to be told no again. Blocks go to the error-handling path, where they reduce rate and alert, as the error taxonomy guide describes.

The field check is what makes this work. A 200 with an empty shell and a 200 with real data look the same to a status-code check, so the probe has to look for the actual fields.

Two lanes, two budgets

Concurrency is where mixed crawls most often go wrong in practice, because the two lanes have very different costs and a single concurrency setting can’t serve both.

The browser lane is bounded by memory and CPU. Each context holds memory and each page holds more. Rendering eats CPU on top. The right limit is a small number of concurrent pages per machine, set by measuring memory under load and leaving headroom. The HTTP lane is bounded by network and by what the target will tolerate. It can run many more concurrent requests, limited mainly by politeness and rate limits.

Share one limit across both and one of two things happens. Set it high for the HTTP lane and the browser lane overcommits memory and starts crashing contexts. Set it low for the browser lane and the HTTP lane crawls at a fraction of the speed it could safely manage.

Give each lane its own budget. In scrapy-playwright that’s the plugin’s context and page limits alongside Scrapy’s own concurrency settings. In a plain-Python design it’s two worker pools with separate sizes.

Rate limits against the target are a shared budget, though. Both lanes hit the same site, and the site sees the total. A per-domain rate limit should count requests from both lanes together, which usually means one rate limiter both lanes consult. Browser renders also generate many sub-requests for assets, which count against the site’s view of your traffic even when your crawler counts one page. Blocking unneeded assets in the browser lane, as the bandwidth guide describes, reduces that load as well as the proxy bill.

Watch for the browser lane becoming the bottleneck that starves the HTTP lane. If detail pages are discovered only from rendered category pages, the HTTP lane can sit idle waiting for the browser to produce URLs. Prioritise discovery pages in the browser lane, or find a cheaper discovery source like a sitemap, so the fast lane stays fed.

Refreshing a session without a stampede

Sessions end. Cookies expire, servers invalidate sessions after inactivity or a fixed time, and some sites log out a session that makes too many requests. In a long mixed crawl, the HTTP lane will eventually get a redirect to the login page, a 401, or a page that renders as logged-out.

Detect it explicitly. Every HTTP lane response should pass a cheap “still logged in” check, such as the presence of an account element or the absence of a login form, for page types that require a session. A status code check alone misses the common case where a logged-out page returns 200.

Refresh through the browser lane. When the check fails, the HTTP worker marks the session as expired and requeues its URL. One browser worker runs the login again and publishes the new session state. HTTP workers pick up the new cookies and carry on.

The trap is the stampede. If fifty HTTP workers each notice the expiry at the same moment and each trigger a login, the site sees fifty logins in a few seconds from one account, which is both wasteful and likely to lock the account. Put a lock around refresh: the first worker to detect expiry takes the lock and triggers one login, and the others wait for the new session instead of starting their own. A version counter on the session makes this simple. Workers record which version they used, and a worker that fails with an old version just waits for the next one.

Limit the retry loop as well. If a fresh login immediately fails the check, stop and alert instead of logging in again. Repeated failed logins usually mean credentials changed, the account was locked, or the site changed its flow, and hammering the login page makes each of those worse.

Monitoring a mixed crawl

A mixed crawl has failure modes neither lane has alone, and the monitoring needs to see both lanes and the boundary between them.

Track the share of pages each lane fetched, per page type and per run. The most common slow failure in a mixed design is the browser lane quietly growing: a probe escalates more pages over time, a new page type defaults to rendering, or someone routes a type to the browser to fix a one-off bug and never routes it back. Each change is small. Together they erode most of the saving, and only a lane-share chart shows it.

Track cost per record per lane. Bandwidth, compute time and proxy spend divided by records produced gives you a number you can compare across runs. When it rises, the lane breakdown tells you where.

Track session events: logins, refreshes, and “still logged in” failures per hour. A rising refresh rate means sessions are getting shorter, which often precedes a site tightening its login rules.

Track field completeness per page type regardless of lane, as the silent-failures guide describes. A page type whose completeness drops right after a routing change points straight at the change.

And keep the logs lane-tagged. When a record is wrong, the first question is which lane fetched its page and with which session version, and that should be one lookup, not an investigation.

What to do on Monday

If you have a crawl that runs entirely in a browser today, here’s how we’d convert it.

List the target’s page types and test each one with a plain HTTP fetch and your existing parser. Write the routing table with a reason per row. Expect most types to land in the HTTP lane.

Pick the wiring that matches your stack. On Scrapy, add scrapy-playwright and set the playwright meta key only for browser-lane page types. On Crawlee, run the HTTP and Playwright crawlers against one request queue. In plain Python, run Playwright for the browser steps and a pooled async client for the rest, with context.request for the odd plain call inside a browser session.

Prove the session handoff on one request before building anything else: browser logs in, one plain request comes back authenticated. Pin both lanes for that session to one sticky exit IP. If the target binds sessions to the client and the handoff fails, keep that target in the browser.

Give each lane its own concurrency budget and share one per-domain rate limiter across both. Add a “still logged in” check, a locked refresh, and a hard stop on repeated login failures.

Then watch lane share and cost per record for a few runs. When the browser share creeps up, find out why before accepting it.

For the rest of the collection stack around a crawl like this, from proxies to parsing to storage, the full set of guides is at Data Research Tools.

Get new guides and videos first — join the Telegram channel.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *