← all guides

How to scrape websocket data without breaking the connection

Most scraping guides assume you’re making a request, getting a response, and moving on. Websockets don’t work that way, and if you try to scrape one with the same playbook you use for HTML pages, you’ll get a connection that dies every few minutes for reasons that look random but aren’t.

I run proxy infrastructure for scraping workloads, and websocket targets are the ones that generate the most confused support tickets. The confusion comes from the connection itself, which has different requirements than a normal HTTP fetch. Here’s what actually changes, and how to build something that stays up.

What makes a websocket different from a normal request

A regular scrape is one TCP connection per request, sometimes reused via keep-alive, but fundamentally short-lived. A websocket starts as an HTTP request (a GET with an Upgrade: websocket header) and then the same TCP connection stays open, sometimes for hours, carrying frames in both directions.

That single fact breaks a lot of assumptions built into standard scraping setups:

  • Your proxy has to hold one TCP tunnel open for the life of the session, not just service one request.
  • Any IP rotation mid-connection doesn’t “refresh” anything, it just kills the socket, because the server was talking to a specific TCP peer.
  • Idle timeouts on the proxy, on your HTTP client, or on the target’s load balancer will all silently close the connection if nothing crosses the wire for a while.

If you’ve scraped REST APIs before, the mental model of “rotate an IP every N requests” has to be thrown out for this. There’s no request boundary to rotate between. There’s just one continuous pipe.

Proxy type matters more here than almost anywhere else

For request-based scraping, rotating residential or datacenter proxies both work fine because each request is independent. For a websocket, the exit IP has to stay assigned to your session for as long as you need the connection open. That means you want sticky sessions, not fast rotation, and you want a proxy type where sticky actually means sticky.

A few things I’ve seen matter in practice:

Datacenter proxies tend to hold long TCP tunnels more predictably because the underlying IP isn’t shared with the churn of a mobile carrier’s NAT pool. If a datacenter proxy says a session is sticky for 30 minutes, it usually is, because there’s no upstream carrier reassigning that address underneath it.

Mobile proxies are attractive for other reasons (residential-looking ASN, carrier-grade NAT blending you in with real phone traffic) but the carrier itself can rotate the underlying IP for reasons that have nothing to do with your proxy provider’s settings. That’s fine for short requests. For a websocket that needs to survive 20 minutes of silence between price ticks, a mid-session carrier IP change will drop your socket even if your provider’s dashboard says “sticky.”

Residential proxies sit in between. Stability depends heavily on the specific pool and how the provider manages IP checkout, which is exactly the kind of thing you should verify against your own connection logs rather than take on faith from a sales page.

None of this means one proxy type is unblockable or the “right” answer in general. It means: if a target streams data over a long-lived socket, test session duration under your actual proxy before you build a pipeline around it, because the failure mode isn’t a blocked request, it’s a connection that just stops.

SOCKS5 vs HTTP proxies for websockets

Websocket traffic can be tunneled through an HTTP proxy using the CONNECT method, the same mechanism used for HTTPS. Most proxy providers support CONNECT on port 443, but not all of them handle long idle periods on that tunnel gracefully, and some enforce a maximum tunnel duration that will close your socket without warning.

SOCKS5 proxies are usually a cleaner fit for websocket work because they operate at the TCP layer rather than parsing HTTP semantics on top of the tunnel. If your library supports SOCKS5 (Python’s websockets library does via a wrapped socket, Node’s ws does through a SOCKS agent), it’s worth testing both and comparing how long the connection actually survives under load, not just at idle.

Either way, check three settings before you assume a proxy will work: max tunnel/session duration, idle timeout, and whether the provider throttles or resets connections that exceed a certain data volume. These specs are rarely advertised prominently, and providers that support one type of scraping well don’t automatically support the other.

Keeping the connection alive

Websocket protocols include ping/pong control frames specifically so both ends can tell the connection is still alive. If your library sends automatic pings, make sure the interval is shorter than any idle timeout enforced by the proxy or any intermediate load balancer. A connection sitting silent for two minutes might get killed by a proxy’s 90-second idle timeout even though the target server would have been happy to keep it open for an hour.

This is also where reconnect logic earns its keep. Any production websocket scraper needs:

  • A ping interval well under the tightest timeout in the chain (proxy, target server, your own client library).
  • A reconnect handler that catches the close event, waits a sane backoff period, and re-establishes the handshake rather than crashing the whole process.
  • Idempotent handling of any subscription or auth message the target expects immediately after the handshake, since you’ll need to replay it on every reconnect.

None of this is about evading anything. It’s the same resilience pattern you’d want for any long-lived network connection, proxy or not. Streaming data sources drop connections for their own operational reasons too: server restarts, load balancer failovers, network blips.

Finding and identifying the endpoint

Before any of the proxy or reconnect work matters, you need the actual websocket URL and handshake details. Browser devtools (Network tab, filtered to WS) show the upgrade request, the frames going each way, and any subscription message the client sends right after connecting. Tools like wscat are useful for confirming you can replicate that handshake manually before wiring it into a script.

Pay attention to what the handshake actually requires: an Origin header, a specific Sec-WebSocket-Protocol, or an auth token embedded in the URL or sent as the first frame after connecting. These aren’t obstacles to work around, they’re part of the target’s expected client behavior, and a client that skips them just won’t receive data, proxy or no proxy.

What responsible use looks like here

Streaming endpoints often carry live pricing, live inventory, or other real-time data that the site owner may license or meter separately from their regular page content. Before scraping any websocket feed, check whether that data is behind a paywall, tied to an account you don’t have rights to use for automated access, or restricted by the site’s terms. A proxy changes where your traffic appears to originate from. It doesn’t change what you’re allowed to do with the data once you have it.

It’s also worth saying plainly: no proxy setup, rotation strategy, or client configuration makes a scraper undetectable or guarantees it won’t get rate limited or blocked. Sites that run real-time infrastructure generally watch connection patterns (reconnect frequency, message rates, header consistency across the handshake and TLS layer) as an operational necessity, since malformed or abusive clients cost them server resources regardless of intent. Building a stable, well-behaved client that respects ping intervals and reasonable reconnect backoff isn’t a workaround for that monitoring. It’s just how you avoid looking like the kind of client that monitoring exists to catch.

Where this leaves you

Scraping a websocket is a different engineering problem than scraping pages, even though people often bolt it onto the same pipeline. The proxy needs to hold a session, not rotate one. The client needs to keep the connection alive on purpose, not by accident. And the data on the other end may come with its own usage rules separate from the page it’s embedded in.

Test session duration against your actual proxy before committing to it, build reconnect logic like you mean it, and check what you’re allowed to do with a live feed before you build a pipeline around it.

If you want more breakdowns like this on the mechanics of scraping at scale, come check out the rest of what we’ve written at Proxy Scraping.

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

proxies
Need proxies that survive the block wall?

Singapore Mobile Proxy runs real 4G/5G mobile IPs on rotating SIMs — the carrier-grade addresses most of these targets still trust.

see plans →
read on
More scraping guides

The rest of the field manual: target-site playbooks, library walkthroughs, provider reviews, and anti-bot troubleshooting.

browse all guides →