Your agent needs a supplier's current pricing tiers, its last three product launches and a verified email for the sales lead by Thursday. Do you point it at an API or at the page?
The standard advice, use the API when the provider has one, answers a smaller question than the one in front of you. It says nothing about what happens when a required field comes back empty, who pays when a run costs ten times the estimate, or what you can prove about the collection when a reviewer asks six months later.
Treat the choice between web scraping and API access as a reliability, cost and compliance decision rather than a technical preference, and most of the hard questions answer themselves. What follows is the reasoning, the failure points and the record you should keep.
Table of Contents
- Which Fits Your Data Need
- How APIs and Web Scraping Share One Mechanism
- Legal and Ethical Limits Before You Collect
- How to Build a Scraping Workflow Step by Step
- Pagination, Rate Limits and Common Failures
- How AI Agents Combine APIs and Scraping
- Choose Your Data Source Before You Build
Which Fits Your Data Need
Start with the short answer. Use an API when the provider already exposes the data you need in a documented, supported form. Scrape only when no suitable endpoint exists and the page is one you're permitted to read.
An API is a service counter. You name the item, you get it back in the format on the menu, and a wrong request returns an error you can act on. Scraping is reading the shop window. What's on display is there because the owner chose to show it, arranged for shoppers rather than for your parser, and the whole display can be rebuilt on a Tuesday without a note to you.
Seven factors separate the two routes when a team has to choose this week.
| Factor | API | Web scraping |
|---|---|---|
| Data source | Endpoint the provider chose to expose | Any page a browser can display |
| Structure | Typed JSON fields with a documented schema | HTML you must parse and map to fields yourself |
| Stability | Versioned, with announced breaking changes | Breaks when page layout or markup changes |
| Access control | API key, quotas and provider terms | Robots directives, site terms, login walls and anti-bot checks |
| Cost driver | Per call or per result, as published | Proxies, compute and time spent maintaining parsers |
| Failure visibility | Error codes and status responses | Silent empty or wrong fields unless validated |
| Best for | Repeatable data the provider already sells | Public data with no API, read within the site's rules |
The cost row is where budgets go wrong most often. An API charges for the answer at a published rate, so you can price a run before you send it. Scraping charges for the attempt: proxies, browser compute, and the engineering hours that go into repairing selectors after a redesign. That second bill arrives late and lands on whoever maintains the parser.
Volume doesn't change the ranking. It changes how expensive the wrong choice becomes.
How APIs and Web Scraping Share One Mechanism
Both routes send an HTTP request and read a response. The difference is who designed the response, and what they promised about it.
An API is a contract. The provider decides which resources exist, which fields each one returns, how you ask, and what an error looks like. When those decisions are written down and versioned, your code depends on a promise instead of a page layout.
That pattern is older than many people assume. REST was developed between October 1994 and August 1995 while HTTP/1.0 and the first HTTP/1.1 proposal were being written, and Roy Fielding's evaluation records web traffic growing from approximately 100,000 requests per day in 1994 to 600,000,000 requests per day in 1999, a 6,000-fold increase in five years (Roy Fielding's dissertation). Generic, cacheable, resource-oriented interfaces were how independently built clients, servers and caches kept talking at that rate.
A price shown twice
Take one product price. On the retail page it sits inside markup built for shoppers: a span, a currency symbol, a strikethrough for the old price, sometimes a JavaScript widget that fills the number in after the page loads. The pricing endpoint returns a record with fields named sku, price and currency, and it keeps those names until the provider announces a version change.
Now redesign the page. The price moves into a client-rendered component and your old selector returns nothing. The parser doesn't crash. It writes an empty value, or captures a neighboring number, and the run reports success.
The endpoint, meanwhile, still returns the same fields for the same resource, because renaming them would break every client that depends on them.
Scraping is the fallback when no contract exists. A fallback needs more validation than a contract does, not less.
Legal and Ethical Limits Before You Collect
Checking robots.txt feels like the compliance box. It isn't one. The Robots Exclusion Protocol is not legally binding, and empirical research found that some bot categories, including AI search crawlers, rarely check robots.txt, with stricter directives sometimes correlating with lower compliance (a 2025 empirical analysis of robots.txt behavior). In June 2025, Cloudflare reported that only about 14% of 3,816 sampled domains with discoverable robots.txt files used directives targeting AI bots.
So the file you're told to check describes a preference. It says little about what you may do with what you collect.
What actually shapes the decision
Terms of service, login boundaries, personal data rules, copyright and database rights, and the jurisdiction where the data gets used all bear on the same call. The analysis gets harder as policy formats multiply: the Simple Licensing specification proposes machine-readable permissions that distinguish AI indexing, AI input and AI training as separate uses.
The practical fix is to write down what you decided and why, per run. Record the site signals you observed, your user agent string, the purpose, the access method, the data categories involved, the timestamp and the decision with its reason. That turns compliance from a disclaimer into an auditable control, and it's the only way a reviewer can reconstruct why a page was collected.
| Situation | Safer route | Record before collecting |
|---|---|---|
| Public page with no API | Scrape within rate limits and the site's terms | Robots signals, terms reviewed, purpose and timestamp |
| Data behind a login | Use an authorized API or a licensed feed | Account authorization and the scope it allows |
| Personal data about individuals | Collect only fields the purpose needs | Data categories, lawful basis and retention limit |
| Site explicitly opts out | Do not collect, route to review | Opt-out signal observed and the decision made |
| Terms unclear or silent | Pause and ask the data owner or legal review | Question raised, who reviewed it and the outcome |
Four defaults cover most ambiguity. Don't bypass technical barriers. Minimize personal data to the fields the purpose needs. Respect an explicit opt-out without arguing about whether it's binding. Route anything unclear to a person rather than to a retry loop.
Our own terms at looot prohibit illegal scraping, bypassing rate limits, reselling access without an agreement, and interfering with the gateway, providers or other customers. A workflow that requires any of those isn't a workflow with a compliance problem. It's the wrong workflow.
If the collection feeds competitive research, AdLibrarySpy's guide to ethical competitor research is a useful companion for deciding which pages are fair game and what to leave alone.
How to Build a Scraping Workflow Step by Step
A scraper that works on one page and fails on the next isn't a scraper. It's a demo. The workflow runs in five broad stages, from confirming an official source to monitoring for drift.

Here is the same sequence at the level of individual engineering steps, with the mistake that usually skips each one.
- Confirm that nothing official returns the fields. Check the provider's documentation and any licensed feed first. Writing a selector for a value that a documented endpoint already serves is the most common wasted week in this work.
- Read the rules before the first request. Robots.txt, the published terms and any API quotas decide what's off limits, and the policy record you keep later depends on what you observed now.
- Request one page and inspect the actual output. Open the rendered HTML rather than a screenshot or a memory of the layout, then locate each field you need in it. Selectors written from the design instead of the DOM are the second most common failure.
- Write a field schema. Name every field, give it a type, and mark it required or optional. A fixed target is what makes validation possible at all.
- Set a request budget per domain and per credential. Cloudflare treats rate limiting as a way to constrain the operations of individual clients and names automated scraping among the behaviors it can limit, so pacing belongs in the design (Cloudflare's rate limiting best practices).
- Validate before you store. Check every required field and mark missing values as missing. Testing only the HTTP status is how a consent wall gets recorded as a product page: the response is a 200, the fields are empty, and the row looks healthy.
- Keep the raw response with its URL, timestamp and status code. Storing only the parsed output makes a bad run impossible to replay or explain later.
- Log the run itself. Pages requested, pages failed, retries and rate-limit responses seen. Failures that live only in a console scrollback didn't happen as far as the next person is concerned.
What a healthy first run looks like
A healthy run returns every required field on most pages, and its failures appear in the log rather than hiding in empty columns. Test on twenty to fifty pages before scaling, then read two parsed records by hand. Careful reading teaches more than a dashboard of green statuses.
Coverage is rarely perfect, and it's worth counting. A long-running academic study of corporate websites requested 169,578 archived website versions and successfully scraped 110,379 of them before moving on to subpages (published scraping research on North American firms). The gap between requested and retrieved is exactly why retry logic and a count of what you missed belong in the build.
The test that matters: if you can't say how many pages a run requested and how many it actually parsed, you have a script with good days, not a pipeline.
If you're deciding whether a page is worth collecting versus waiting for a provider to publish it as an endpoint, Agentable's look at scraping tools and agent readiness covers where the two routes converge.
For a walkthrough of the same sequence in practice, this video covers building the workflow end to end.
Pagination, Rate Limits and Common Failures
Pagination looks like a response-format detail and behaves like a correctness control. Get it wrong and the run finishes cleanly with a dataset missing a third of its records.
The default page size is usually smaller than the job. GitHub's REST API returns 30 issues per page by default, even when a repository holds more than 1,600 open issues, and clients follow the HTTP Link header to keep going, generally asking for up to 100 items with per_page (GitHub's pagination documentation). Bigger pages cut request overhead and connection latency. They also raise memory pressure, timeout exposure, and the amount of work lost when one page fails mid-run.
Cursors beat offsets once the collection moves
An offset tells the server to skip the first N records. If another writer inserts or deletes a record while your run is in progress, the window shifts and you collect duplicates or holes. A cursor represents a position in the provider's ordered stream, so it survives concurrent changes far better. Persist it after every successful page rather than at the end of the run, and make page processing idempotent on a stable record ID so a replay doesn't double-count.
Watch for parameters that get reduced without notification. GitHub lowers a per_page value above its maximum instead of returning an error, so the only way to know what you received is to inspect the response size and the pagination headers, not the value you requested.
Rate limits are feedback control, not a fixed number
Bots generated 49.6% of global internet traffic in 2023, the highest level recorded by Imperva since it began monitoring automated traffic in 2013, according to Thales' 2024 announcement. At that volume, providers read unnamed automated requests as a reason to slow you down, and a fixed high concurrency setting is the fastest way to look like the traffic they built defenses for.
A burst triggers throttling, your retries amplify the burst, your IP reputation decays, and successful throughput falls while nominal concurrency climbs. Use a token bucket per host, cap concurrency, add exponential backoff with jitter, and honor Retry-After on 429 responses instead of retrying immediately.
| Symptom | Likely cause | Fix |
|---|---|---|
| Same records appear twice | Offset pagination shifts when records are inserted or deleted | Switch to cursor pagination or deduplicate on a stable record ID |
| Records missing after the first pages | Server reduced the requested page size without an error | Check the actual page size and follow the Link header to the next page |
| Bursts of HTTP 429 responses | Fixed high request rate and retry storms | Token bucket, honor Retry-After, lower per-domain concurrency |
| Successful responses with empty fields | Page rendered by JavaScript or blocked by a consent wall | Use the official endpoint or browser rendering, and fail the record if required fields are empty |
| Stale values in the output | Cached responses reused past their useful life | Store the fetch timestamp and set a refresh rule per field type |
| One domain stalls the whole run | Shared retry and connection pool across targets | Separate budgets per domain and per credential |
Each row is cheaper to fix before the first production run than after a downstream report has been built on broken output.
How AI Agents Combine APIs and Scraping
An agent doesn't choose a data source the way you do. It sees the tools you registered, reads their descriptions and input schemas, and emits a call. Your application executes that call and returns text or JSON. Reliability has to live in that loop, because the model can't inspect a proxy pool or read a rate-limit header.

What one call looks like
Say an agent is profiling a company for a sales team. It calls a structured company-data endpoint over MCP and gets back a record with revenue band, headcount and a timestamp on each field. Those timestamps matter. A headcount updated eight months ago should carry less weight in the summary than one updated last week.
Then a required field comes back null. The agent has three honest options: retry with a narrower request, fall back to scraping the company's public pricing or about page, or return an uncertainty signal. What it must not do is invent the value or pass a blank cell downstream.
Prefer the API for structured, repeatable fields. Use scraping for the gaps, on pages that are public and permitted. Tag anything scraped with the method, the source URL and the time, and lower the confidence of any conclusion that leans on it. If neither route produces the field, say so in the output. A fast wrong answer costs an agent more than an explicit gap, because every later step inherits it.
Benchmark by intent, not by someone else's success rate
A 2025 independent comparison found that only four tested web-scraping APIs opened more than 80% of target pages, and none were adequate for agentic Google access at a median response time of 5.05 seconds (Proxyway's 2025 web scraping API report). Treat aggregate success numbers as a warning sign, because a tool can retrieve a page and still hand your agent something unusable through JavaScript rendering, a consent wall, lost structured data or a stale result.
Test the operations you run, separately. Single-page extraction, discovery, search-result retrieval, monitoring and high-volume collection fail in different ways, and a tool that wins one of those routinely loses the others. Report field-level accuracy, freshness and latency percentiles rather than a single headline figure.
That's also why many teams put one access layer in front of several providers. looot gives an agent one key and one prepaid balance for the paid data APIs of many providers, with per-call prices shown before each run. The layer solves reach and billing. Your team still owns field validation and the record of what each run collected.
Choose Your Data Source Before You Build
Three questions decide this week's build, and none of them require a benchmark.
- Does a provider already return these fields as a documented endpoint? If yes, start with the API and set a budget per call.
- Is the target page public, and are you permitted to read it? If yes and no endpoint exists, build the small scraper from the workflow above.
- What happens when a field is missing or wrong? If the honest answer is that the agent carries on regardless, fix that before you collect anything.
Answer them on paper, field by field, before you write code. List the fields you need, mark each as API-available or scrape-only, and note which ones the downstream decision depends on. The fields that carry the decision get validation first.
For agent projects, connect the tools through MCP and keep keys, price quotes and run records in one place, the way the agent section describes. Then run the first validated test this week on twenty to fifty pages. Reading two records by hand will settle more arguments than another week of provider comparison.
The source that passes all three questions with the fewest exceptions is the one to build on first. Fewer exceptions means fewer silent failures, and silent failures are what turn a data pipeline into a source of confident wrong answers.
Picking the source is one decision; running it cheaply and provably is the next. looot puts 3,000+ paid data operations across search, scraping, company and social data behind one key and one prepaid balance, quotes the price before each run and keeps a ledger of what ran and what it cost. If you'd rather compare the API route and the scraping route inside one workspace than sign up with six providers this week, start there.



