Web scraping with residential proxies: a practical Python setup
One requests Session per visitor, rotating or sticky by task, country tags, retries with backoff, per-domain limits and a bandwidth budget in gigabytes.
Check that geo-targeted creatives, landing pages and disclaimers render in each country, state or city, with a checklist, a Python script and the limits.
A geo-targeted campaign is supposed to show this creative in Texas, that landing page in Quebec and this disclaimer wherever the regulator demands it. The only way to see what Texas gets is to load the page from Texas. Residential proxies do that from a household address in each market.
Ad servers, landing-page builders and consent platforms all decide what to show from the visitor's address before anything else. Country, often region and city, come from a geolocation lookup on the IP; the creative, the currency, the legal footer and sometimes the whole page variant follow from that. Your office connection, your cloud test runner and your colleague's phone are three fixed places, and none of them is the audience.
A residential exit is a household connection in the place you name. On GhostConnect, the place is a tag on the password: _country-US, then _state-texas and _city-houston to narrow it. State and city need a country, place names are lowercase with spaces as dots, and the pool spans 195 countries. One set of credentials covers every market, so a check across eight countries is eight passwords built from the same account, not eight orders.
Fetching the landing page from a server in the right country is cheaper and simpler, and it is often the wrong test. A hosting range is classified as a hosting range by the same databases the ad stack uses for geolocation. Fraud filters treat traffic from those ranges as non-human by default, so an ad slot may show a fallback, a house ad or nothing, and a landing page may serve the variant it keeps for crawlers. The address also geolocates to the facility, which is rarely the city a local campaign targets. The page loads, and it is still not the page a person in Houston gets. A GhostConnect datacenter proxy is fine for checking that a page is up from one of 6 countries (United States, Canada, United Kingdom, France, Netherlands, Germany) at $3.99 per IP per 31 days, but it will not show you the market's version of the page.
A residential exit changes only the address. That is what the geo decision keys on, so it is enough for the checks below, though not for everything an ad decision depends on (see the last section).
A verification visit is a short flow: confirm the exit, load the page, perhaps follow the click-through. Those requests must leave from the same household, or you will confirm a Texan address and then load the page from Ohio. Use a sticky session, _lifetime-5_session-ID with an id of 6 to 15 letters, digits or dashes, and keep the lifetime short: five minutes covers a check. A new session id on the next check gives you a different household, which is what you want, because checking the same page from the same address every hour only ever samples one household.
A sweep of many pages, each checked once with nothing to carry between them, is a rotating job: leave the lifetime and session off and every request leaves from a new household in the tagged place. The sticky-session guide has the full set of rules. The API builds the strings too, with the session id generated for you:
curl -H "Authorization: Bearer $GT_KEY" \
"https://ghostconnect.com/api/v1/proxies/residential/obcl4126/connection-string?session=sticky&minutes=5&country=ca&state=quebec&city=montreal"
Record these on every check, for each market, so you can show afterwards why a check passed or failed.
lang attribute on the html element or the page's hreflang set. A 200 in the wrong language is a failure.fr-CA. If your check sends English, a page that keys on the header will answer in English whatever the address.The script below takes a URL, loads it once per market through a sticky residential session, and prints one line per market: country, exit address, status, language attribute, a short hash of the normalised body and the final URL, plus any required text that was missing. The markets, the language headers and the required strings are the parts you edit.
import hashlib
import re
import secrets
import sys
import requests
HOST, PORT = "residential.ghostconnect.com", 1080
USER, PASS = "rJxYKRe2U", "Yxa5WGCUkvP9km" # documentation credentials: use your own
# One row per market: the country tag, an optional state and city, and the language a local browser sends.
MARKETS = [
{"country": "US", "state": "texas", "city": "houston", "lang": "en-US,en;q=0.8"},
{"country": "CA", "state": "quebec", "city": None, "lang": "fr-CA,fr;q=0.9,en;q=0.5"},
{"country": "DE", "state": None, "city": None, "lang": "de-DE,de;q=0.9"},
{"country": "AU", "state": None, "city": None, "lang": "en-AU,en;q=0.8"},
]
# Text that must appear for the market, for example the local disclaimer. Empty list = hash only.
MUST_CONTAIN = {
"US": ["Terms and conditions apply"],
"CA": ["Des conditions s'appliquent"],
"DE": ["Es gelten die Teilnahmebedingungen"],
"AU": ["Terms and conditions apply"],
}
def visitor(market, minutes=5):
"""A sticky visitor: the exit check and the page fetch must leave from the same household."""
pw = PASS + "_country-" + market["country"]
if market["state"]:
pw += "_state-" + market["state"]
if market["city"]:
pw += "_city-" + market["city"]
pw += "_lifetime-%d_session-%s" % (minutes, secrets.token_hex(4)) # 8 hex characters: a valid session id
url = "http://%s:%s@%s:%d" % (USER, pw, HOST, PORT)
s = requests.Session()
s.proxies = {"http": url, "https": url}
s.headers.update({"User-Agent": "your-client-name/1.0", "Accept-Language": market["lang"]})
return s
def normalise(html):
"""Strip the parts that change on every load so two identical pages hash the same."""
html = re.sub(r"<script\b.*?</script>", "", html, flags=re.S | re.I)
html = re.sub(r'name="csrf[^"]*"\s+value="[^"]*"', "", html)
return re.sub(r"\s+", " ", html)
def check(url, market):
s = visitor(market)
exit_ip = s.get("https://ifconfig.me/ip", timeout=30).text.strip()
r = s.get(url, timeout=30)
body = normalise(r.text)
return {
"country": market["country"],
"exit": exit_ip,
"status": r.status_code,
"final_url": r.url,
"lang_attr": (re.search(r'<html[^>]*\blang="([^"]*)"', r.text) or [None, "?"])[1],
"hash": hashlib.sha256(body.encode("utf-8")).hexdigest()[:12],
"missing": [t for t in MUST_CONTAIN.get(market["country"], []) if t not in r.text],
}
if __name__ == "__main__":
url = sys.argv[1]
rows = [check(url, m) for m in MARKETS]
for row in rows:
print("%(country)s %(exit)-15s %(status)s %(lang_attr)-6s %(hash)s %(final_url)s" % row)
if row["missing"]:
print(" missing:", "; ".join(row["missing"]))
if len({r["hash"] for r in rows}) == 1:
print("every market received the same page")
Most pages carry something that changes on every load: a CSRF token, a nonce, a request id in a script tag. Hash the raw HTML and every fetch differs, so the comparison tells you nothing. That is why the script normalises the body before hashing it: it strips script blocks and CSRF fields and collapses whitespace, and your pages may need more removed. Establish the noise floor first, by fetching from one market twice with two session ids:
# Two fetches from the same market, two session ids. Different hashes mean the page is noisy, not the market.
for i in 1 2; do
curl -s -x http://residential.ghostconnect.com:1080 -U "rJxYKRe2U:Yxa5WGCUkvP9km_country-DE_lifetime-5_session-check$i" \
https://www.example.com/lp/winter | tr -s '[:space:]' ' ' | sha256sum
done
If those two hashes differ, widen the normalisation, or stop hashing the whole page and compare only the parts the targeting is meant to change: the disclaimer block, the price element, the creative URL. A whole-page hash is a shortcut that only works on stable pages; the per-element checks are the ones to rely on.
Residential bandwidth is $2.99 per GB, never expires, and is bought 1 to 1,000 GB at a time. A verification programme is light on data compared with scraping, because it fetches a small number of pages often rather than many pages once. A worked example, with the assumptions stated: 12 landing pages, 8 markets, checked 3 times a day, at about 600 KB transferred per check including the exit lookup and the connection overhead. That is 288 fetches and about 173 MB a day, 5.2 GB over 30 days. Round up to whole gigabytes and the month costs $17.94 for a 6 GB order.
Run the same checks through a real browser that also downloads the creative, the stylesheets and the scripts, and the per-check size is closer to 2500 KB in this example, which makes the month about 22 GB and $65.78. That is still small next to a media budget, and all of the increase is page weight. Keep the requests-based script for the text and redirect checks, and reserve the browser for the creatives that are only inserted client-side. How much bandwidth a page costs goes deeper into page weights and what to block.
Because the plan never expires, buying a few gigabytes ahead costs nothing but the float, and the dashboard shows usage per hour so a check that starts fetching a heavier page is visible before it empties the plan. The API returns the same series and takes top-ups.
The address is only one input. Ad decisions also key on the user agent, the language header, screen size, cookies and consent state, logged-in status, frequency caps, the referrer, the time of day and whether JavaScript ran at all. A requests fetch has no cookies, runs no scripts and declares whatever user agent you give it. It will show you the server-rendered page and the redirect chain for a visitor at that address; it will not show you a creative that is inserted by a script after load, a consent-gated variant, or what a returning visitor with a frequency cap sees.
For those, drive a browser through the same proxy string, with the market's language, a clean profile per check, and the consent choices a local would make, and accept that the result is still one device's view. A single fetch samples one home, so run the check more than once, from more than one household, before deciding that a market is broken; a new session id per check is all that takes.
None of this needs an account with a name on it. GhostConnect accounts are a random key, paid in crypto or by card on Stripe's page, and the network records the destination and status code of each request and nothing else; the privacy page is the full list. Get a key, buy the gigabytes the arithmetic above says you need, and start with the two-fetch noise test on one landing page before wiring up every market.
One requests Session per visitor, rotating or sticky by task, country tags, retries with backoff, per-domain limits and a bandwidth budget in gigabytes.
Residential, ISP and datacenter prices at GhostConnect and IPRoyal, bandwidth rules, what sign-up asks for, how you pay and what each keeps, checked 2026-10-24.
The usage and proxy detail endpoints, a Python script that polls remaining_gb and tops up below a threshold, how often to poll, and what a top-up costs.