Boolean X-ray
Search:
Lead Cost
$2 → $0.05
Traditional lead gen tools filter pre-scraped databases and give you either too few results or too much garbage. I built a scraper using Google's Discovery Engine that searches the actual web with surgical precision — and cut lead costs from $2 to $0.05 per enriched contact.
The Problem
If you've ever tried to generate B2B leads at scale, you know the pain. Most lead gen tools (Apollo, ZoomInfo, LinkedIn Sales Navigator, etc.) give you fancy filters and promise precision targeting. In practice? You get one of two outcomes:
- Overly strict filters → 12 results when you need 1,200
- Loose filters → 10,000 garbage leads that don't match your ICP
The real issue is that these platforms index their own databases. If someone's profile isn't tagged correctly, or they use a non-standard job title, or the tool's AI misclassified them, you miss them entirely. You're searching a subset of a subset.
I needed something better. Something that actually searches the web the way Google does.
The Solution: Boolean X-ray Search
Instead of relying on pre-filtered databases, I built a scraper that uses Boolean X-ray search against Google's Discovery Engine API. This lets me craft surgical search queries that find LinkedIn profiles directly from Google's index.
Here's an example query:
# Surgical targeting with Boolean operators
QUERY = '("Loan Broker" OR "Mortgage Broker" OR "Mortgage Loan Originator") "California" "NMLS"'This finds anyone on LinkedIn who mentions being a loan broker, mortgage broker, or MLO, is in California, and has NMLS licensing. No reliance on how LinkedIn tagged their profile. No hope that Apollo's scrapers got it right. Just raw Boolean logic against the actual web.
Why This Works Better
1. You're searching the actual web, not a stale database
Google indexes LinkedIn profiles constantly. If someone updated their title yesterday, it's findable today. Traditional tools? They might not refresh that profile for weeks or months.
2. Boolean logic is infinitely flexible
Want to find "growth marketers" OR "demand gen managers" OR "marketing ops" in SaaS companies that mention "PLG" or "product-led"? Easy:
QUERY = '("growth marketer" OR "demand gen" OR "marketing ops") ("PLG" OR "product-led growth") site:linkedin.com/in/'Try doing that with dropdown filters.
3. No artificial limits
Most tools cap you at 2,500 results per search or charge per credit. With this approach, I'm only limited by API quotas (which are generous) and how long I'm willing to let the script run.
The Architecture
The script does a few key things:
Stateful Pagination with Page Tokens
This was critical. Google's API returns results in pages (10–50 per page). Most scripts just loop through pages in one run and call it a day. Problem: if you want 10,000+ leads, you'll hit rate limits or timeouts.
Solution: save the page token after each run.
def save_last_page_token(path: str, token: str | None):
if token:
with open(path, "w", encoding="utf-8") as f:
f.write(token)
else:
if os.path.exists(path):
os.remove(path)Now I can run the script in batches:
- Run 1: Fetch pages 1–10, save token
- Run 2: Resume from page 11, fetch 11–20, save token
- Run 3: Resume from page 21…
Each run grabs 100 leads (10 pages × 10 results). I can run this on a cron job or manually whenever I want more data. No lost progress. No duplicate API calls.
Deduplication
Lead gen tools love to charge you for the same lead twice. I built dedup at the script level:
def load_existing_links(csv_path: str) -> set[str]:
if not os.path.exists(csv_path):
return set()
links = set()
with open(csv_path, "r", newline="", encoding="utf-8") as f:
reader = csv.DictReader(f)
for row in reader:
link = (row.get("Link") or "").strip()
if link:
links.add(link)
return linksBefore adding a new result, we check if the LinkedIn URL already exists. This means:
- You don't pay email finder tools to enrich the same person twice
- Your CSV stays clean
- You can run the script multiple times without bloat
Clean Data Export
Results go straight to CSV with three columns: Name/Title, Link, Snippet. This CSV then feeds into Hunter.io, Snov.io, Apollo's enrichment API, or whatever email finder you prefer.
The Full Pipeline
Total cost: Google API usage (cheap) + email finder credits (way cheaper than buying full leads). Total control: 100%.
Configuration
The script is stupid simple to customize:
PROJECT_ID = "your-gcp-project"
LOCATION = "global"
ENGINE_ID = "your-search-engine-id"
QUERY = "your-boolean-query-here"
PAGES_PER_RUN = 10 # How many pages per execution
PAGE_SIZE = 10 # Results per pageChange the QUERY and you're targeting a completely different ICP. Change PAGES_PER_RUN to control how aggressive each batch is.
Lessons Learned
Rate limiting is your friend
I added a 0.8-second delay between pages:
time.sleep(0.8)Without this, you'll hit API rate limits fast. This small delay keeps you under the radar and prevents failed requests.
Page tokens can expire
Google's page tokens don't last forever (usually 24–48 hours). If you pause for too long between runs, you might need to start fresh. Not a huge deal since you've already saved previous results, but worth noting.
Garbage in, garbage out
Your Boolean query is everything. A bad query returns bad leads. Spend time refining it. Test variations. Add negative keywords if needed (-"seeking opportunities" filters out job seekers).
Why This Matters
Most devs building lead gen tools treat it like a data engineering problem: scrape, parse, store, repeat. That's fine, but if your source is limited, you're just building a faster path to mediocre data.
By going directly to Google's index with Boolean logic, you're working with the most comprehensive, up-to-date dataset available. You're not constrained by someone else's taxonomy or refresh cycle. And by building stateful pagination and deduplication into the script, you're not just collecting leads — you're building a reusable, scalable system that gets better over time.
The script is on GitHub. Modify the query, point it at your GCP project, and start building your own lead database.