Skip to content

Latest commit

 

History

History
124 lines (93 loc) · 3.66 KB

File metadata and controls

124 lines (93 loc) · 3.66 KB

Python (apify-client) — Website Contact Scraper

Call Website Contact Scraper from Python with the official apify-client. This is client-side only — you call the Actor on the Apify platform and read back the results.

1. Install

pip install apify-client

2. Instantiate with your token

Get your token from Apify Console → Settings → Integrations. Prefer an environment variable over hard-coding it.

import os
from apify_client import ApifyClient

client = ApifyClient(os.environ["APIFY_TOKEN"])  # or ApifyClient("YOUR_TOKEN")

3. Run the Actor and iterate the dataset

import os
from apify_client import ApifyClient

client = ApifyClient(os.environ["APIFY_TOKEN"])

# Realistic input: scan homepages + Contact/About pages
run_input = {
    "startUrls": [
        {"url": "https://apify.com"},
        {"url": "https://www.stripe.com"},
        {"url": "https://www.example-agency.com"},
    ],
    "maxDepth": 1,
    "maxRequestsPerCrawl": 40,
    "useJsBrowser": False,
    "proxyConfiguration": {"useApifyProxy": True},
}

# Start the run and wait for it to finish
run = client.actor("logiover/website-contact-scraper").call(run_input=run_input)

# Iterate results (one item per page)
for item in client.dataset(run["defaultDatasetId"]).iterate_items():
    print({
        "domain": item.get("rootDomain"),
        "pageType": item.get("pageType"),
        "emails": item.get("emails"),
        "phones": item.get("phones"),
        "linkedin": item.get("socials", {}).get("linkedin"),
        "instagram": item.get("socials", {}).get("instagram"),
        "title": item.get("pageTitle"),
    })

4. Empty input for a demo crawl

Call with no input to run the small demo crawl and preview the output:

run = client.actor("logiover/website-contact-scraper").call()

for item in client.dataset(run["defaultDatasetId"]).iterate_items():
    print(item)

5. Build a CRM-ready lead list

Keep only companies with an email or LinkedIn URL, then flatten to rows:

leads = []

for item in client.dataset(run["defaultDatasetId"]).iterate_items():
    emails = item.get("emails") or []
    phones = item.get("phones") or []
    socials = item.get("socials") or {}

    if emails or socials.get("linkedin"):
        leads.append({
            "domain": item.get("rootDomain"),
            "email": emails[0] if emails else "",
            "phone": phones[0] if phones else "",
            "linkedin": socials.get("linkedin", ""),
            "instagram": socials.get("instagram", ""),
            "company": item.get("pageTitle", ""),
            "source": item.get("url"),
        })

print(f"Qualified {len(leads)} leads")

6. Export to CSV

Write the qualified leads straight to a CSV file for import into a CRM or sequencer:

import csv

with open("contacts.csv", "w", newline="", encoding="utf-8") as f:
    writer = csv.DictWriter(
        f,
        fieldnames=["domain", "email", "phone", "linkedin", "instagram", "company", "source"],
    )
    writer.writeheader()
    writer.writerows(leads)

Input reference

Field Type Default Notes
startUrls list of { "url": ... } demo crawl Websites to scrape.
maxDepth int 01 1 0 = homepage only; 1 = also Contact/About pages.
maxRequestsPerCrawl int 200 Page budget per run.
useJsBrowser bool False Enable only for JS-rendered sites returning empty pages.
proxyConfiguration dict {"useApifyProxy": True} Apify Proxy settings.

▶️ Run it: https://apify.com/logiover/website-contact-scraper