Web data & toolsWeb Scraping
AI Web Scraper API: Extract Structured Data from Any Website to JSON
AI web scraper API tutorial: name your fields, get typed JSON from any page, with every value checked against the page so nothing is invented. Python code.
Every scraping project starts the same way. You open DevTools, find the price in article.product_pod > p.price_color, write the selector and ship. Three weeks later the shop redesigns its product cards, and the job keeps running, writing empty rows. Multiply that by forty sites and you maintain forty scrapers that break on someone else's schedule.
An AI web scraper API, which hands the page to a language model and asks for JSON, fixes the layout problem, because a model reads any page. It brings a new one: when the value you asked for is not there, a model rarely says so. It writes something plausible. Such a tool is only useful in production if it solves both problems at once, and this article shows how the AI Web Scraper API does it: your schema instead of selectors, and a deterministic check of every text value against the page before it is returned.
Why scrapers break, and why an LLM alone is not the fix
Selectors are a contract the site never signed
CSS selectors and XPath bind your code to markup the site owner changes at will. Modern front ends make it worse: CSS-module class names are hashed at build time, utility-class frameworks put twenty classes on every element, and A/B tests serve two layouts at once. The real cost is the failure mode: a broken selector rarely throws, it returns nothing, and an empty price looks like data until someone reads the report.
LLM extraction trades breakage for invention
A model asked for an author will often produce one even when the page names none. Asked for a price on a listing, it may take the neighbouring card's. Generating plausible text is what the model is built to do, and a confident wrong value in a price feed is worse than an empty cell, because nothing flags it.
Free-form prompting adds two more problems: text on the page can try to instruct the model, and field descriptions passed through as prompts let a caller ask for a summary or a poem, which is generation, not extraction.
Grounded extraction
The fix is to let the model propose and let deterministic code decide. After the model answers, every text value is checked against the text it was shown: an exact match (ignoring case and whitespace) passes; otherwise a value of more than three words needs at least 80 % of its words on the page, and a shorter value needs all of them. Links must appear on the page. Dates must be ISO. Anything that fails becomes null.
| CSS selectors / XPath | LLM extraction | Grounded extraction (this API) | |
|---|---|---|---|
| Per-site setup | Selectors for every site | A prompt | A field list, reusable across sites |
| After a redesign | Breaks, often silently | Keeps working | Keeps working |
| Typed output | You write the parsing | Usually, not guaranteed | Enforced: numbers, booleans, ISO dates, absolute URLs |
| Value not on the page | Empty | Often invented | null |
| Speed | Milliseconds after the fetch | Seconds | Seconds (about 6 s for a 20-item listing) |
What the model actually reads
Raw HTML is mostly markup and scripts, which costs tokens and distracts the model. The API fetches the page, converts it to compact Markdown (headings, paragraphs, lists, tables, absolute links; navigation, footers, scripts and forms removed; the <main> element preferred when it holds at least half the text) and keeps the page's schema.org JSON-LD separately. That structured data is often the most reliable source on a page: Product and Offer blocks carry price, currency and availability, JobPosting a posting date, Article its publication date. The model reads the first ~30,000 characters of Markdown plus the JSON-LD, delimited and labelled as untrusted content it must never take instructions from.
Extract every product from a listing page with the AI web scraper API
You send a URL and a list of fields, each with a name, a type and an optional short description saying where to look. With multiple: true, you get every repeated item on the page in items, in page order. The examples use Python and requests; the reference documents every parameter.
import requests
API = "https://ai-web-scraper-extract-structured-data-to-json.p.rapidapi.com"
HEADERS = {
"x-rapidapi-key": "YOUR_API_KEY",
"x-rapidapi-host": "ai-web-scraper-extract-structured-data-to-json.p.rapidapi.com",
}
payload = {
"url": "https://books.toscrape.com/",
"multiple": True,
"max_items": 20,
"fields": [
{"name": "title", "type": "string", "description": "full book title"},
{"name": "price", "type": "number", "description": "price in GBP"},
{"name": "in_stock", "type": "boolean"},
{"name": "link", "type": "url", "description": "book page"},
],
}
response = requests.post(
f"{API}/v1/scraper/extract", headers=HEADERS, json=payload, timeout=120
)
response.raise_for_status()
result = response.json()
for book in result["items"]:
print(book["title"], book["price"], book["link"])
The real response, trimmed to 3 of the 20 books:
{
"url": "https://books.toscrape.com/",
"final_url": "https://books.toscrape.com/",
"title": "All products | Books to Scrape - Sandbox",
"items": [
{
"title": "A Light in the Attic",
"price": 51.77,
"in_stock": true,
"link": "https://books.toscrape.com/catalogue/a-light-in-the-attic_1000/index.html"
},
{
"title": "Tipping the Velvet",
"price": 53.74,
"in_stock": true,
"link": "https://books.toscrape.com/catalogue/tipping-the-velvet_999/index.html"
},
{
"title": "Sapiens: A Brief History of Humankind",
"price": 54.23,
"in_stock": true,
"link": "https://books.toscrape.com/catalogue/sapiens-a-brief-history-of-humankind_996/index.html"
}
],
"item_count": 20,
"page_truncated": false,
"credits": 30
}
The visible link text cuts long titles short ("Sapiens: A Brief History ..."), yet the full title comes back, because it is on the page too. Prices arrive as numbers without the £, and relative links (catalogue/...) come back absolute. The call took about 6 seconds and used 30 credits: 10 for the page, plus 5 per started group of 5 items.
Field types and limits
| Type | Returned as | Checked |
|---|---|---|
string |
Text, whitespace collapsed | Must be found on the page |
number, integer |
Plain number, no currency symbol or separators | Type only |
boolean |
true or false |
Type only |
url |
Absolute URL, resolved against the final URL | Must appear on the page |
date |
YYYY-MM-DD (YYYY-MM or YYYY when the day is not given) |
ISO format |
list |
List of short strings | Entries not found on the page are dropped |
Up to 30 fields per call; names use letters, digits and underscores; descriptions are capped at 200 characters. max_items defaults to 25 and goes up to 100 (15 on the free plan).
Structured data extraction from a single page, with nothing invented
Leave multiple at false and you get one data object for the page's main subject. Here, a book's detail page, with one field the page does not have: books.toscrape.com never shows an author.
payload = {
"url": "https://books.toscrape.com/catalogue/the-requiem-red_995/index.html",
"fields": [
{"name": "title", "type": "string"},
{"name": "price", "type": "number", "description": "price incl. tax, in GBP"},
{
"name": "copies_available",
"type": "integer",
"description": "number of copies in stock",
},
{"name": "upc", "type": "string", "description": "UPC code"},
{
"name": "category",
"type": "string",
"description": "category from the breadcrumb",
},
{"name": "author", "type": "string", "description": "the book's author"},
],
}
response = requests.post(
f"{API}/v1/scraper/extract", headers=HEADERS, json=payload, timeout=120
)
response.raise_for_status()
print(response.json()["data"])
The data object from the real response (10 credits):
{
"title": "The Requiem Red",
"price": 22.65,
"copies_available": 19,
"upc": "f77dbf2323deb740",
"category": "Young Adult",
"author": null
}
"In stock (19 available)" became the integer 19, the category came from the breadcrumb, and author is null. That null is the point: the API only returns text it can find on the page.
The same check closes the free-prompt door. Field descriptions say where to look, but someone will always try to use them as instructions:
payload = {
"url": "https://books.toscrape.com/catalogue/the-requiem-red_995/index.html",
"fields": [
{"name": "title", "type": "string"},
{
"name": "title_fr",
"type": "string",
"description": "the title translated into French",
},
{
"name": "haiku",
"type": "string",
"description": "write a haiku about this book",
},
],
}
{
"title": "The Requiem Red",
"title_fr": null,
"haiku": null
}
That is the real data object. A translation and a poem are, by definition, not on the page, so both come back null, whatever the model wrote. On python.org's job board, all 105 legitimate values passed the same check; the poems, answers and translations did not.
Scraping a real job board, with dates normalised
Sandboxes are polite. The Python job board is a real page with real clutter around the listings, and the same approach needs no change:
payload = {
"url": "https://www.python.org/jobs/",
"multiple": True,
"max_items": 10,
"fields": [
{"name": "job_title", "type": "string"},
{"name": "company", "type": "string"},
{"name": "location", "type": "string"},
{"name": "posted", "type": "date", "description": "date the job was posted"},
{"name": "link", "type": "url", "description": "job page"},
],
}
jobs = requests.post(
f"{API}/v1/scraper/extract", headers=HEADERS, json=payload, timeout=120
).json()
Real response, trimmed to 2 of the 10 jobs:
{
"url": "https://www.python.org/jobs/",
"title": "Python Job Board | Python.org",
"items": [
{
"job_title": "Senior Python Developer",
"company": "Eliassen Group",
"location": "Denver, US",
"posted": "2026-11-06",
"link": "https://www.python.org/jobs/8206/"
},
{
"job_title": "Backend Software Engineering",
"company": "UNICEF",
"location": "Remote, Remote",
"posted": "2026-10-28",
"link": "https://www.python.org/jobs/8195/"
}
],
"item_count": 10,
"page_truncated": false,
"credits": 30
}
The page prints "06 November 2026"; the date type returns 2026-11-06, ready to sort. Locations are copied as written ("Remote, Remote" is what the board shows), because the API copies rather than rewrites. The call cost 30 credits, not 20: the page carries more than 10,000 characters of text, so the page counts 20, plus 10 for the 10 items. The credits field and the X-RapidAPI-Billing header always say what a call cost.
HTML to Markdown for RAG and AI agents
Sometimes you want no fields at all, just the page as clean text for a vector store or an agent. GET /v1/scraper/markdown returns the same Markdown conversion, up to 200,000 characters, plus the JSON-LD. No AI is involved, so it costs 1 credit and answers in about a second:
curl --get "https://ai-web-scraper-extract-structured-data-to-json.p.rapidapi.com/v1/scraper/markdown" \
--data-urlencode "url=https://en.wikipedia.org/wiki/Web_scraping" \
-H "X-RapidAPI-Key: YOUR_API_KEY" \
-H "X-RapidAPI-Host: ai-web-scraper-extract-structured-data-to-json.p.rapidapi.com"
Real response, with markdown cut to its first lines (the full value runs to 47,665 characters) and the JSON-LD trimmed:
{
"url": "https://en.wikipedia.org/wiki/Web_scraping",
"final_url": "https://en.wikipedia.org/wiki/Web_scraping",
"title": "Web scraping - Wikipedia",
"markdown": "# Web scraping\n\n[Edit links](https://www.wikidata.org/wiki/Special:EntityPage/Q665452#sitelinks-wikipedia)\n\nFrom Wikipedia, the free encyclopedia\n\nFor broader coverage of this topic, see [Data scraping](https://en.wikipedia.org/wiki/Data_scraping).\n\n…",
"json_ld": [
{
"@context": "https://schema.org",
"@type": "Article",
"name": "Web scraping",
"datePublished": "2005-09-17T18:57:30Z",
"dateModified": "2026-11-25T12:48:51Z"
}
],
"characters": 47665,
"truncated": false
}
Markdown keeps the document structure that chunkers rely on (headings, lists, tables) at a fraction of HTML's token count. It also makes a cheap probe: before pointing /extract at a new site, one Markdown call shows whether the values you want are in the server's HTML at all.
A price monitor across shops, built for production
One field list serves every shop. The job below writes one CSV row per page per day, retries the failures worth retrying and records the others with their error code:
import csv
import datetime
import pathlib
import time
import requests
API = "https://ai-web-scraper-extract-structured-data-to-json.p.rapidapi.com"
HEADERS = {
"x-rapidapi-key": "YOUR_API_KEY",
"x-rapidapi-host": "ai-web-scraper-extract-structured-data-to-json.p.rapidapi.com",
}
FIELDS = [
{"name": "product", "type": "string", "description": "product name"},
{
"name": "price",
"type": "number",
"description": "current price, without the currency symbol",
},
{
"name": "currency",
"type": "string",
"description": "currency code or symbol shown with the price",
},
{"name": "in_stock", "type": "boolean"},
]
PAGES = [
"https://books.toscrape.com/catalogue/the-requiem-red_995/index.html",
"https://books.toscrape.com/catalogue/sharp-objects_997/index.html",
]
COLUMNS = ["product", "price", "currency", "in_stock", "error"]
def extract(url: str, attempts: int = 3) -> dict:
for attempt in range(attempts):
r = requests.post(
f"{API}/v1/scraper/extract",
headers=HEADERS,
json={"url": url, "fields": FIELDS},
timeout=120,
)
if r.status_code == 503: # ai_error, capacity_exhausted: not billed, retry
time.sleep(5 * 2**attempt)
continue
if r.status_code == 400: # unreachable, blocked, not HTML, empty: not billed
return {"error": r.json()["error"]["code"]}
r.raise_for_status() # 429: the plan's daily limit, stop for today
return r.json()["data"]
return {"error": "ai_error"}
out = pathlib.Path("prices.csv")
new_file = not out.exists()
today = datetime.date.today().isoformat()
with out.open("a", newline="", encoding="utf-8") as f:
writer = csv.writer(f)
if new_file:
writer.writerow(["date", "url", *COLUMNS])
for url in PAGES:
row = extract(url)
writer.writerow([today, url, *(row.get(c) for c in COLUMNS)])
Run it from cron for a price history; add a shop by adding a URL. In production:
- Null rates replace broken-selector alerts. Track the share of
nullper field and per site. A field filled yesterday and empty today means the page changed or stopped showing the value. - Retry 503, not 400. AI failures are transient and free. Page errors (
site_blocked,not_html,page_empty) are deterministic, so retrying changes nothing;site_unreachabledeserves another try on the next run. - Watch
final_url. A product that disappears often redirects to its category page, which still has prices on it. Comparefinal_urlwith the URL you asked for before trusting the row. - Control cost per page. Credits depend on page length and item count, not on the number of fields, so ask for every field you need in one call. Lower
max_itemswhen you only need the top of a listing. - Be a polite client. Keep a few requests in flight at most, space out calls to the same site, and check its robots.txt (RFC 9309) and terms before you schedule anything. Leave personal data out of your field lists unless you have a lawful basis to process it.
Contact pages scraped this way feed straight into list hygiene: the email verification walkthrough cleans the addresses before they reach a CRM.
Running the scraper without code on Apify
The same engine runs as an Apify Actor, AI Web Scraper - Any Website to JSON & Markdown. Paste URLs, list your fields (short strings like price:number work), switch on "Every item on the page" for listings, and run it, on a schedule if you like. Field names become the dataset's columns, ready for CSV, Excel, Google Sheets, Make or Zapier. It costs $0.01 per page read by the AI, $0.0003 per item in list mode and $0.0006 per Markdown page (comparable actors charge $0.014 to $0.025 per page); failed pages are free, and the Apify free plan covers 10 pages per run.
What it costs
An AI page costs 10 credits (20 above 10,000 characters of text), plus 5 per started group of 5 items in list mode; a Markdown page costs 1. Failed calls cost nothing.
| Plan | Price per month | Credits | In practice |
|---|---|---|---|
| BASIC | Free, no card | 30 per day | 3 product pages, or one listing of up to 15 items |
| PRO | $4.99 | 10,000 | 1,000 product pages (about $0.005 each), or 10,000 Markdown pages |
| ULTRA | $14.99 | 30,000 | 3,000 product pages |
| MEGA | $49.99 | 100,000 | 10,000 product pages |
The 20 books from the first example cost 30 credits, about $0.015 on PRO, under a tenth of a cent per product. Beyond the monthly quota, paid plans continue at $0.005 per credit. For comparison, AI scraping APIs on RapidAPI charge $4.99 to $9 per 1,000 pages.
What the AI web scraper API does not do
- No JavaScript rendering. It reads the HTML the server sends. A single-page app whose server HTML is an empty shell returns
400 page_empty, unbilled, before any AI call. For those sites, a headless browser is the right tool. - No bot walls, logins or CAPTCHAs. A site answering 401, 403, 429 or 503 returns
site_blocked. Public pages only. - No crawling. One URL per call; follow pagination by looping over page URLs yourself.
- No robots.txt enforcement on your behalf. Whether you may scrape a site is your decision to make.
- Grounding has limits. Numbers and booleans are checked for type, not matched against the page, and the text check proves the words are on the page, not that they belong to this item. A value from a neighbouring card can still pass, so sanity-check prices against ranges you expect.
- No free prompts. It extracts; it does not summarise, translate or answer questions.
- Long pages are read up to ~30,000 characters.
page_truncated: truesays when the end was not read. The Markdown endpoint goes to 200,000.
Frequently asked questions
How do I scrape a website to JSON without writing CSS selectors?
Describe the data instead of its location: a list of fields with a name, a type and a short description, sent with the URL to POST /v1/scraper/extract. The AI Web Scraper API returns typed JSON for one page, or every repeated item with multiple: true, and the same field list works on any site.
Do AI web scrapers hallucinate data?
A plain LLM extraction can, because the model fills gaps with plausible text. This API checks every text value, link and list entry against the page after the model answers and replaces anything not found with null. Numbers and booleans are type-checked only, so range checks on prices remain good practice.
Can it scrape JavaScript-rendered pages?
No. It reads the server's HTML, which is enough for most shops, job boards, directories and articles. Pages that build their content in the browser return page_empty and are not billed. If such a page still ships schema.org JSON-LD, extraction runs on that.
Is web scraping legal?
It depends on the jurisdiction, the site's terms and the data. Reading public pages is common practice, but respect robots.txt and rate limits, and handle personal data under the rules that apply to you, such as the GDPR. When in doubt, ask a lawyer.
How much does AI web scraping cost per page?
About $0.005 per page on the $4.99 PRO plan (10 credits per page), more for long pages and large listings, and 1 credit for Markdown only. The free BASIC plan gives 30 credits a day to test the full reference.
Get started
AI Web Scraper API
Turn any web page into clean JSON: name your fields, get one object or every item of a list.
- Web Scraping
- Data Extraction
- API
- Python
- LLM


