Home  ›  Blog

Deploying Scalable Python Workflows & Scraping

Python workflows and scraping pipelines
A pipeline that runs itself — and tells you when it needs attention.

Most businesses do not have a data problem. They have a copying problem: someone opens the same ten pages every morning, copies the same fields into a sheet, and hopes nothing was missed. A pipeline replaces that morning with a script that does it the same way every time.

We build these pipelines with Python and Playwright, and we run them on our own stack rather than on someone's laptop. What follows is the order we build in — collect, parse, queue, store, schedule, deploy, monitor.

Collect: open the page the way a visitor sees it

Most modern pages are not plain HTML: the content loads after JavaScript runs, so a plain HTTP request returns an empty shell and a script that parses it finds nothing. A headless browser waits for the content to actually appear and behaves like a visitor instead of a hammer. That is why our collectors run on headless Playwright.

The first version of a collector should be small enough to read in one sitting:

import asyncio
from playwright.async_api import async_playwright
async def collect(url):
    async with async_playwright() as p:
        browser = await p.chromium.launch(headless=True)
        page = await browser.new_page()
        await page.goto(url, wait_until="networkidle")
        await page.locator(".listing-card").first.wait_for()
        rows = []
        for card in await page.locator(".listing-card").all():
            name = await card.locator(".name").inner_text()
            price = await card.locator(".price").inner_text()
            rows.append({"name": name.strip(), "price": price.strip()})
        await browser.close()
        return rows

Three details do most of the work: waiting for the network to settle, so the page is not read until its requests have finished; waiting for the first listing card, so a slow page gets time instead of an empty result; and closing the browser, because one left open on a server is a slow leak that only shows up days later.

Parse: pull out only the fields you need, then clean them

A collector that saves raw page text is just a hoarder. The parser decides, field by field, what counts: name, price, phone number, date — and nothing else. If no one downstream will read a field, it does not get stored.

Raw pages are messy in predictable ways: prices carry currency symbols and trailing slashes, phone numbers arrive with spaces and dashes, dates come in three formats on the same site. The parser normalises all of it before anything is stored — one format for money, one for phone numbers, one for dates.

Two fields show the whole job — the rules, written out, are the cleaning step:

Raw textStoredRule
Rs. 1,450/-1450Strip "Rs.", commas and "/-"; store an integer in rupees
+91 880-858-8153918808588153Strip spaces and dashes; drop the leading "+"; keep the country code

The same rules run on catalogue data for a 143-medicine pharmacy platform we built, where prices and names arrive in just as many shapes. This is the part people skip, and it decides whether the data is usable — a sheet full of almost-right rows is worse than no sheet at all, because it looks finished.

A Python scraping workflow running on a laptop
The collector runs on a schedule — no browser open on anyone's desk.

Queue: let the work wait its turn

Sites go down, pages change shape, networks drop. A pipeline that stops at the first error is a pipeline you have to babysit, so every job goes through a queue: the collector puts URLs into a Redis queue, a worker takes one and runs it, and a failed page waits and tries again later instead of taking the whole run down with it.

Retries need a limit and a backoff: a failed page is tried a small number of times with a growing wait between attempts, then goes to a dead-letter list that a person actually reads. A job that retries forever is not resilient, it is a loop. A parser that meets a changed page shape logs exactly what it expected and what it found, instead of crashing silently.

Store: one place where clean rows land

The store depends on who reads the data. For a small team it is a Google Sheet they already open every day, with new rows appended and a run log on a second tab. For anything bigger it is SQLite on the server, or Supabase when several tools need the same rows at once — the same code writes to either. Both options live in one codebase, so a project can start small and move up without a rewrite.

Whatever the store, two rules hold. Every row carries the run it came from and the source URL it was read from, so a wrong number can be traced back to its page. And the store is append-only in practice: rows are updated by key, never deleted and re-added, so history survives and a bad run can be rolled back.

Schedule: run it when nobody is watching

A pipeline that needs someone to press run is a checklist, not automation. The schedule is Linux Cron — a line in the crontab that runs the collector when the business needs it, usually early morning so the sheet is full before the team arrives. Cron is boring, and that is the point: no dashboard to check, no app to open.

The schedule also sets the politeness budget. A run that visits a source once a day with a pause between requests is a visitor; one that fires a hundred requests a minute is an attack, and gets blocked like one.

Deploy: from a laptop script to a server that survives a reboot

The jump from "works on my laptop" to "runs every day" is a deployment problem. Our path is deliberately plain: the code lives in GitHub, GitHub Actions runs the checks and ships it on every merge to the main branch, and it lands in a Docker container on a VPS. No step in that chain needs a person to remember a command.

Docker earns its place because Playwright needs a real browser, and browsers need system libraries that differ between a laptop and a server. The container carries the browser with it, so the run that passed on the build server is the run that executes on the VPS — and a server reboot does not end the pipeline, it resumes on the next scheduled run.

Scale: add workers, not aggression

When a pipeline needs to cover more sources, the answer is more workers, not faster requests. Redis holds the queue, so a second worker can start on the same VPS — or a second VPS — and take jobs from the same list, with no code change. Watch queue depth: if it grows faster than the workers drain it, add a worker.

The limits that do not move are the polite ones. robots.txt is checked before a source is added and respected in the collector, and the pause between requests stays even with ten workers — ten polite workers are still polite, and one aggressive one gets the project blocked. LeadForge Engine, our own lead-generation tool, runs the same way: fifteen modules and roughly two thousand lines of Python, a Google Places scraper and a Playwright auditor, with a WhatsApp bot that sends only approved messages inside warm-up caps.

Monitor: a failed run must be loud

Every run leaves a log: when it ran, how many rows it found, what failed, and how long the queue took to drain. The notifier — a WhatsApp message on a bad run, silence on a good one — is wired to the log, not to someone's memory. A quiet failure is how you discover three weeks later that the data stopped on a Tuesday.

What to do next

If your team still copies data by hand every morning, write down the source, the fields, and how often you need them — that is the whole brief. We build the pipeline from it and hand over the run log with it. Python Automation starts at ₹7,999: start with our Python Automation service, get an instant estimate, or tell us the source on WhatsApp.