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 each of our actors with a proxy setting starts on the cheapest network the site accepts and moves to Apify Proxy only when the site blocks it: a first run should not pay for a proxy it does not need.
written
14 min readGoogle Maps scraper in Python: 120 places a search, phones in the data, no review counts
A Google Maps search lists 120 places and stops. Signed out, most cards show no phone and almost none a review count, but the JSON the page loads has a phone for 65 to 100 % of the places. How to read it with Playwright within robots.txt, and what to clean before it goes into a CSV.
8 min readInstahyre API in Python: skills, experience and company size of Indian jobs
Instahyre job pages fill their lists from a JSON search that needs no login. We read 240 postings for Python, React, data engineer and sales: the skills they ask for, the years of experience, the size of the employer, how many are remote and how old they are. How to read it, and the traps.
6 min readjobs.ch jobs in Python: the workload is a range, and the start date is not a start date
A jobs.ch search page carries its 20 jobs as data. Half or more give the workload as a range, 80 to 100 % most often. The job pages add structured data for search engines, but it seldom has a pay figure and a start date that is the posting date plus 30 days. How to read both, and what to keep.