Proxies: use the cheapest tier that answers
Direct first, then datacenter, then residential. Residential traffic is billed by the gigabyte, so the ladder is a cost control as much as a technique.
A proxy is not a switch you turn on. It is a bill. Residential proxies in particular are charged by traffic, and a browser run that loads every image and font on every page can spend more on bandwidth than the data is worth.
The ladder#
We try the cheapest tier first and climb only when the page does not come back.
import httpx
LADDER = ("direct", "datacenter", "residential") # proxies["direct"] is None
async def fetch_with_ladder(url, proxies):
for tier in LADDER:
async with httpx.AsyncClient(proxy=proxies.get(tier), timeout=30, headers={"User-Agent": UA}) as client:
resp = await client.get(url)
if resp.status_code == 200 and not looks_blocked(resp.text):
return tier, resp
if resp.status_code == 404:
return tier, None # the page is gone, a better proxy will not bring it back
raise Blocked(f"{url}: no tier got a real page")Two details carry the weight:
- A 404 ends the climb. A better proxy does not bring back a deleted page. Without that line, every dead link in a catalogue would be tried on the most expensive tier.
- "No tier got a real page" raises
Blocked. That is the same exception the wall check uses (see robots.txt first). The run stops and reports; it does not keep trying.
Cheaper than a better proxy: not downloading things#
For browser runs, the biggest saving is blocking images, media and fonts. The data is in the document. The pictures are the bandwidth. Blocking them is a few lines of configuration, and it cuts traffic on residential tiers by more than any proxy negotiation will.
What the platform adds#
Residential proxy is a paid-plan feature on Apify and is billed by traffic. That is one more reason the default input of every actor runs direct: a first run with no proxy should work, and a buyer should switch proxies on deliberately.
written
7 min readRemote job APIs: five free feeds, and the catch in each
Remote OK, We Work Remotely, Jobicy, Working Nomads and Arbeitnow publish their jobs without a key. What each feed holds, how far back it goes, the terms, and sixty lines of Python that put them in one list.
5 min readFacebook Ad Library API: which ads you get, which you don't
Meta's API returns political ads from everywhere and every kind of ad shown in the UK or the EU. An ad shown only in the US for running shoes is not in it. What each way into the Ad Library gives you, and how to keep the ads the API leaves out.
6 min readFree exchange rate API with no key: ECB rates in Python
The European Central Bank publishes its daily euro rates as plain files: no key, no sign-up. What is in them, the three things that trip people up (weekends, holidays, retired currencies) and about forty lines of Python that handle all three.