An Agent Skill that teaches an AI agent to build ExtractHub extractors: it inspects the page you name, picks the cheapest fetch mode that works (plain HTML, embedded JSON, JSON API, JavaScript rendering, XHR capture, browser actions), writes the extractor definition, validates it, uploads it as a private draft, tests it and releases it when you say so. Ask your agent things like: - "Create an Extr
npx mdskills install extracthub-io/extracthub-extractor-builderRelated
1---2name: extracthub-extractor-builder3description: Builds, tests and uploads ExtractHub extractors (web scraping definitions of request options + CSS/JSON field config that turn a page type into structured JSON). Use when the user wants to create, build, write, fix or improve an ExtractHub extractor, scrape a site or page type "with ExtractHub", turn product / listing / article / job / search pages or a JSON API into JSON through ExtractHub, or upload / release an extractor to ExtractHub (with or without the ExtractHub MCP server).4---56# ExtractHub extractor builder78An ExtractHub extractor is a JSON definition: how to fetch a page (request options) and how to turn it9into JSON (`extractorConfig`). Callers run it on any URL of the same page type through the ExtractHub API or10MCP `extract` tool. Your job: write a definition that is correct on the real page, validate it, upload it,11test it, and release it only when the user agrees.1213Reference files (read when needed):14- [references/config-reference.md](references/config-reference.md): every field shape, extract type, JSON path rule and transform (incl. the ones with options: `split`, `after`, `before`, `between`, `nth`, `removeQueryParams`; no regex).15- [references/request-options.md](references/request-options.md): sample pages (raw vs rendered), proxy, JS rendering, browser actions, XHR, POST, country, price tiers, Studio import file.16- [references/selectors-and-pitfalls.md](references/selectors-and-pitfalls.md): supported selector syntax, stable selectors, engine pitfalls.17- [references/troubleshooting.md](references/troubleshooting.md): empty fields, wrong values, blocked pages, JS-only content, API errors.18- [references/releasing-and-versions.md](references/releasing-and-versions.md): draft, pins, semver, visibility.19- [examples/](examples/README.md): six complete definitions (static list, product detail, JSON API, embedded JSON, JS-rendered, POST API).2021Multi-step scrapes (a list page, then every detail page it links to, into one dataset) are pipelines: build each22extractor here, then follow the **extracthub-pipeline-builder** skill to chain them.2324## Workflow2526Copy this checklist and keep it updated:2728```29Extractor progress:30- [ ] 1. Page type, example URL(s) and fields agreed31- [ ] 2. Page saved to a sample file; fetch mode chosen (HTML / embedded JSON / JSON API / JS / XHR)32- [ ] 3. Definition written33- [ ] 4. Validated on the sample file (scripts/validate.mjs, or local checker) and fixed34- [ ] 5. Uploaded as private draft; live-tested on @draft; output matches the dry run35- [ ] 6. Released (only with the user's OK); pins explained36```3738### 1. Clarify (ask only what is missing)39- Page type and one or two example URLs (a real URL is required; a second URL of the same type catches40 page-specific selectors).41- The fields the user wants. If they only name the page type, propose a short default set (e.g. product:42 name, price, currency, originalPrice, inStock, images, url) and confirm it.43- List page or detail page? For lists: one object per item, plus `nextPageUrl` if it paginates.44Do not ask about request options; you decide them in step 2.4546### 2. Inspect the target page47Save the page to a FILE the way ExtractHub would fetch it (no browser first), one file per example URL:48```bash49curl -sL -A "Mozilla/5.0" "<url>" -o samples/page-1.html50```51This raw HTML is your validation sample for a plain fetch. Keep it on disk: step 4 sends it to the validator52with `scripts/validate.mjs`, so you never paste a page into a tool call. Then decide53(details and how to save a rendered sample: references/request-options.md, "Sample pages"):54551. Is the data in the raw HTML? → plain fetch, no JS. If the site is open (your curl got the real page, no56 captcha or bot wall), the direct tier (`useProxy: false`) is cheapest and a failed direct call is not57 charged, so it is worth one live test; otherwise, or if that test is blocked, `useProxy: true`.582. Is it in a `<script>` JSON block (`application/ld+json`, `script#__NEXT_DATA__`, `window.__STATE__ = {...}`,59 `self.__next_f.push`)? → still a plain fetch, read it with `jsonContent`. Often the most stable source.60 A list in that JSON: one `jsonPath` with `[*]` + JSON `subFields` (config-reference, "Lists from embedded61 JSON"), so the page stays on the plain-fetch price instead of the JavaScript tier.623. Does the URL return JSON, or does the page load its data from a JSON API you can call directly? →63 `sourceType: "json"` on that URL.644. Only an empty shell / skeleton in the raw HTML? → `renderJavascript: true` + a `wait_for_element`65 browser action. Save the RENDERED DOM to a second file (Playwright `page.content()`, or66 `document.documentElement.outerHTML` from a browser tool written to disk) and compare it with the raw67 file: data only in the rendered one confirms JS is needed. Write selectors and validate against the68 rendered file, still limited to the supported selector syntax. Never validate a plain-fetch extractor69 against a rendered DOM (selectors on JS-added elements pass the dry run and come back empty live), and70 never take a sample from a logged-in or personal browser profile.715. Data only in background responses → `renderJavascript` + `captureXhr` + `xhrUrlFilter`, `sourceType: "json"`.726. Clicks / scrolling / typing needed → `browserActions` (needs `renderJavascript`).737. Blocked or captcha HTML → keep `useProxy: true`, add `allowJsEscalation: true` or `proxyCountry`.748. Your own fetch is blocked, or only shows a JS wall ("enable JavaScript", a consent page)? That says75 little about what ExtractHub's proxy gets: scraping providers often receive the full HTML without a76 browser (Google Search does). Do not jump to `renderJavascript`: get a sample THROUGH ExtractHub with77 `useProxy: true` and no JS (references/request-options.md, "Samples through ExtractHub"; one `premium`78 call). Switch to JS only if that sample lacks the data too. Do not work around the block yourself79 (spoofed User-Agents, "no-JS" variants of the site): the extractor would not fetch that way.809. Data that only loads after a click (a transcript, "show more" reviews)? Check that request in a local81 browser first (DevTools Network). If it answers 4xx to an automated browser (the YouTube transcript82 request returns 400), the site protects it: stop there and tell the user, before spending JS-tier83 calls on `browserActions`.8410. Big sites may give automated traffic other links than a browser sees, e.g. opaque redirect links85 (Google `/goto?url=<token>`) instead of the target URL. Check a live sample through ExtractHub before86 promising the real URL in a field.8788Price tiers (names as `get_account` returns them): `direct` (`useProxy: false`, no JS) < `premium`89(`useProxy: true`, no JS) < `premium_js` (JS rendering, XHR capture or browser actions, always through the90proxy). Use the JS tier only when 1-3 fail, also through the proxy (point 8). If your curl is blocked but a91browser shows data, assume the extractor needs the proxy (and maybe JS); a browser that loads fine hides92that block, which is why the raw sample comes from curl.9394### 3. Write the definition95Start from the closest file in [examples/](examples/README.md). Shape:9697```json98{99 "name": "Example shop - product page",100 "description": "Name, price and stock of an example.com product page.",101 "slug": "example-shop-product",102 "url": "https://example.com/p/123",103 "method": "GET",104 "useProxy": true,105 "renderJavascript": false,106 "extractorConfig": {107 "version": "v1.0",108 "fields": [109 { "name": "name", "selector": "main h1", "extract": "textContent", "transforms": ["normalizeWhitespace"] },110 { "name": "price", "selector": "main [itemprop=\"price\"][content]", "extract": "attributeValue", "attributeName": "content", "transforms": ["toNumber"] },111 { "name": "inStock", "selector": "main link[itemprop=\"availability\"][href$=\"InStock\"]", "extract": "exists" }112 ]113 }114}115```116117Rules that matter most:118- Lists: ONE field with `isArray: true`, `extract: "innerHTML"`, a selector matching each item (not the119 wrapper, no ads), and `subExtractor.fields` with selectors relative to the item.120- Only supported selectors: no `+`, `~`, `:has()`, `:last-child`, `:contains()`, XPath. A non-array field121 takes the FIRST match: scope to the main content.122- Prefer stable hooks: `#id`, `[data-testid]`, `[itemprop]`, semantic tags; avoid generated classes.123- Machine-readable values: attributes (`content`, `datetime`, `data-src`), current price not the struck one,124 `toAbsoluteUrl` on links/images, `extractPrice` on prices, `exists` for booleans.125- `attributeValue`: require the attribute in the selector (`a[href]`), else a missing attribute yields `"null"`.126- Names: camelCase, one per value, stable (renaming later is a breaking version). If the user names the127 fields themselves (`author_url`), use their names: camelCase is the default, not a rule over the user128 (the local checker then warns; the server accepts any name).129- Pick the most faithful source: the same value often exists twice (a video description in the player JSON130 vs the rendered, truncated one). Prefer the structured source that holds the full value.131- Sites that may answer a bot check, consent wall or partial page with HTTP 200 (YouTube132 `playabilityStatus`, consent walls): mark the core fields `required: true` and add a status field from the133 source that is always present (e.g. `playabilityStatus.status`). A required field without a value fails the134 request (`required_fields_missing`), still charged because the page was fetched; batch and pipelines retry it135 once. In list items, `required` on a sub-field drops incomplete items instead, and `includePosition: true`136 numbers the rest (references/config-reference.md, "Required fields and list positions").137- `required: true` = the field must have a value on every page of this kind: an empty value fails the API138 request (422 `required_fields_missing`, charged when the scraping service was billed) and an empty value in a139 health probe makes the version `broken` (2 failing probes in a row). Mark the 1-3 fields that prove the page140 was parsed (title / name / id / price on a product page); do not mark everything. Leave optional any field a141 valid page may lack (ratings, discounts, zestimate, sale price, secondary images): null is then a normal value142 and never affects health. Health marks a version broken only when a required field is empty, a required list143 is empty `[]`, or nothing at all was extracted (references/releasing-and-versions.md, "Health checks"). An144 optional list may be empty; on a list page mark the main list `required` (an empty main list = broken page).145- Never put secrets (cookies, tokens) in headers or body; public and unlisted definitions are visible.146- Custom `headers` (the `Cookie` header included) are not sent when the request goes through the scraping147 proxy (`useProxy: true`); they are only sent on direct requests (`useProxy: false`). Scraping providers manage148 headers for ban avoidance. A JSON API that needs auth headers must use `useProxy: false`. On direct requests149 add only what the target needs; overriding User-Agent or Accept* may get the request blocked150 (references/request-options.md).151152### 4. Validate and iterate153**With an API key** (`EXTRACTHUB_API_KEY` in the environment; free, test keys work too): run the real engine154on the saved sample file. The script calls the MCP tool `validate_extractor_config` for you, reading the155sample from disk:156```bash157node scripts/validate.mjs my-extractor.json --html samples/page-1.html --url "<the page's url>"158node scripts/validate.mjs my-extractor.json --sample-json samples/response.json # sourceType "json"159```160It prints errors, warnings and per field what the dry run extracted (array lengths, which sub-fields are161empty in how many items); `--out result.json` keeps the full result, `--strict` also fails on warnings.162Exit 0 = valid. Calling the MCP tool `validate_extractor_config` directly with `sample_html` is equivalent,163but only for small pages: never retype or paste a large page into a tool call.164165Read every error and warning and the dry-run output; fix and repeat until:166- no errors; every requested field has the expected value on the sample;167- list lengths equal the number of real items on the page; no wrong first matches.168A `sample_empty` warning means the field matched nothing on this sample. Fix it, unless the value is169genuinely absent on this page (`nextPageUrl` on the last page, `originalPrice` without a sale): then confirm170it on a second page where it exists. The validator's `next_steps` names the empty fields, but read every171warning yourself, not only `next_steps`. Validate against a second URL's sample too when you have one.172Big sites (search engines, marketplaces, social networks) serve different layouts per request (A/B173layouts), so results can differ per call. Sample 3-5 live fetches (a small batch of the same URL, or a few174`extract` calls on `@draft`), compare their layouts and validate on each; when a live run differs from the175dry run, get a sample of that response before changing selectors.176177**Without an API key**: run the bundled structure checker, then check selectors yourself against the saved HTML178(e.g. search the HTML for each class / attribute; count list items):179```bash180node scripts/check-config.mjs my-extractor.json181```182It checks keys, types, option combinations and unsupported selectors (exit 0 = OK). It does not run183selectors; tell the user the definition is unverified until it runs in ExtractHub.184185### 5. Upload and live-test (MCP)1861. `create_extractor` with the definition fields (`name`, `description`, `url`, `method`, `body`, `headers`,187 `useProxy`, `renderJavascript`, `captureXhr`, `xhrUrlFilter`, `browserActions`, `proxyCountry`,188 `allowJsEscalation`, `waitForSelector`, `waitTime`, `extractorConfig`, `category`, `tags`, `slug`, `visibility`). Keep `visibility`189 private unless the user asked otherwise. `category` is one value from the "Catalog category" table in190 references/request-options.md (e.g. `travel`, not `Travel & Hospitality`). The slug can only be set here (later it is fixed). Note the191 returned extractor id `@user/slug`. Creating, updating and releasing need a LIVE API key: with a test key192 (`exth_test_...`) these tools answer `live_key_required` and only `validate_extractor_config` works.193 A `validation_error` lists the failing paths in `details.errors`; `slug_taken` / `invalid_slug`: pick another.1942. Call `get_account` (free). If `balance_usd` is 0 on a live key, do not try `extract`: stop at the draft,195 run the release dry run (step 6) on your sample, and tell the user a top-up is needed for the live test.196 Otherwise tell the user a live test is a billed extract call (`direct`, `premium` or `premium_js` tier, see197 step 2; `get_account` shows the prices), then run `extract` with198 `extractor_id: "@user/slug@draft"` and the example URL. A test API key only returns simulated data: a live199 key is needed to see real output.2003. Compare with the dry run. If they differ or fields are empty, see references/troubleshooting.md, fix the201 definition, `update_extractor`, and test again. Stop after a few rounds and report what still fails.202 Need the page the live run saw? `extract` with `raw_html: "link"` returns `raw_html_url` (full HTML, 1 h),203 never a separate probe extractor.2044. Drafts you created only to probe or that you gave up on: `delete_extractor` (dry run first, then205 `confirm: true`). It only deletes private drafts that were never released; tell the user what you deleted.206207### 6. Release (only when the user agrees)208`release_extractor` creates an immutable version (first one `1.0.0`; later bumps follow the output-schema209change). Like the Studio, it checks the draft on a sample page first: pass your sample file through the210script, or `fetch_sample: true` to let ExtractHub fetch the example URL once (one billed extract; tell the211user), or `sample_from_job_id` / `sample_from_batch_item` to reuse the stored result of one of your own212runs of the draft (free; a job that stored the page re-runs the full check, otherwise the stored extraction213must come from the current draft config). A page over the 2,000,000 character `sample_html` limit: `extract` it214with `raw_html: "link"` and pass the returned link as `sample_raw_html_url` (no size limit; same full check; also on215`validate_extractor_config`). Run the dry run first and show the user the planned version and schema diff:216```bash217node scripts/validate.mjs --release @user/slug --html samples/page-1.html218```219then, after the user's OK, the same command with `--no-dry-run` (plus `--bump` / `--changelog` when needed),220or the MCP tool `release_extractor` without `dry_run`. Optional: `bump` (may raise, never lower: `bump_too_low`),221`changelog` (`changelog_required` when a version needs one). `nothing_to_release` means the draft equals the222latest version; `release_check_failed` lists what blocks it (fix with `update_extractor`). Explain: consumers should call `@user/slug@1` (latest 1.x, gets fixes, never breaking changes) or an223exact `@user/slug@1.0.0`; `@draft` is owner-only. Ask before switching visibility to `unlisted` or `public` (public only after a release, else `release_required`).224The extractor's catalog page shows the latest release's sample: its "Extracted Data" is the sample output of the225release check and its source preview is the sample page the check ran on. So release with a representative page226(full data, not an empty or blocked one), ideally of the example `url`. The release answer's `warnings` say when227it is not: `no_preview_page` (a stored extraction only: `sample_from_batch_item`, or a job without the page) and228`preview_url_differs` (the sample page is not the example url). Fix both with `set_preview_page`.229After a release, `set_sample_output` replaces a version's sample (shown on its page and returned to test230keys) with a real result of exactly that version (a job / batch item run with `@user/slug@1.0.0` or `@1`).231`set_preview_page` (live key, owner, exact version `@user/slug@1.0.0`) replaces the version's preview page and, by232default, its sample output from the same page, without a new version: `source: "fetch"` (one billed extract of the233example url, or `url`; tell the user), `"sample_html"`, `"job_id"` (your job that stored the page) or `"raw_html_url"`.234Run it with `dry_run: true` first (price, page size, extracted fields; nothing fetched). `get_extractor` shows each235version's `preview` (`available`, `source_url`, `fetched_at`, `size`). After `update_extractor` changes `url`, the236released preview still shows the old page until you call `set_preview_page`.237Details: references/releasing-and-versions.md.238239### Without the MCP server240With an API key but no MCP connection (e.g. a client that only supports OAuth connectors), steps 4 and 6241still work through `scripts/validate.mjs`: it talks to the MCP endpoint itself. Uploading then goes through242the Studio import below. Deliver:2431. The definition JSON (validated with `scripts/check-config.mjs`, and with `scripts/validate.mjs` when a key is available).2442. A Studio import file: `node scripts/check-config.mjs my-extractor.json --studio-out my-extractor.studio.json`.245 The user opens ExtractHub → Extractor Studio → ⋮ menu → **Import**, picks the file, checks the preview on246 the fetched page, then **Save** (and Release). Browser actions are not in the import file: tell the user247 to add them in the Studio "Browser actions" panel (list them).2483. How to connect the MCP server next time (see the skill README): it makes steps 4-6 automatic.249250## Final answer to the user251Report: the extractor id and pins (if uploaded), fetch mode and why, the fields with a sample of the real252output, the price tier (direct, standard or JS), anything unverified or fragile (generated classes, positional253selectors), and the next step (release, or fixes needed).254
Full transparency — inspect the skill content before installing.