Skip to content

Example Scrapers

The two example Scrapers in the Scwrap repository, earthquakes and kitchen-sink, their Releases, and what their items contain. Your own Scrapers live in your own repository.

The Scwrap repository keeps two Scrapers. earthquakes is the template for your own: it reads the public USGS earthquake feed with one HTTP request and shows the whole shape: a package that owns its Definition, schemas, Implementation and tests, and a Worker release declared apart from it. kitchen-sink uses every Capability the SDKs offer, so one Run on an instance shows which of them work there.

Your own Scrapers live in your Scraper repository, one package each, with their Releases in its releases package (Installation). Each Scraper defines its own input, output and error schemas, even where fields agree with another Scraper's.

earthquakes ​

PartValue
Package@scwrap/earthquakes
DefinitionEarthquakes in definition.ts
Input (EarthquakeQuery)minMagnitude: significant, 4.5 or 2.5; period: hour, day or week
Output (Earthquake)id, time (ISO UTC), magnitude, place, latitude, longitude, depthKm, tsunamiFlag, url
ErrorsBlocked, QuotaExhausted, RateLimited, SchemaDrift, UpstreamDown
ImplementationUsgsFeedLive in usgs-feed.ts. Requires HttpClient.
Releaseearthquakes, a Worker release, revision v1

UsgsFeedLive fetches https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/{minMagnitude}_{period}.geojson and emits one item per feed event, in feed order. HTTP 402, 403 and 429 fail as QuotaExhausted, Blocked and RateLimited; every other non-2xx status and every transport error fails as UpstreamDown. A body that is not the expected GeoJSON fails as SchemaDrift.

The package also has a /schema export with the Definition and schemas alone: @scwrap/earthquakes/schema exports Earthquakes, EarthquakeQuery and Earthquake. A caller that only wants types imports that and pulls in no scraping code.

On the instance ​

The Release is declared in instance-earthquakes.ts and listed in instance-scrapers.ts, the Scwrap repository's catalog:

ts
import { Deployment } from "@scwrap/deploy";
import { Earthquakes, UsgsFeedLive } from "@scwrap/earthquakes";
import { FetchHttpClient } from "effect/http";

export default Deployment.worker({
  implementation: UsgsFeedLive,
  module: import.meta.url,
  scraper: Earthquakes,
  services: FetchHttpClient.layer,
});

It provides FetchHttpClient.layer, so it fetches directly from Cloudflare.

Run it in code ​

Example (Running the Earthquakes Scraper in process)

ts
import { Scraper } from "@scwrap/domain";
import { Earthquakes, UsgsFeedLive } from "@scwrap/earthquakes";
import { Effect, Layer, Stream } from "effect";
import { FetchHttpClient } from "effect/http";

const items = await Effect.runPromise(
  Stream.runCollect(
    Scraper.run(Earthquakes, { minMagnitude: "significant", period: "week" })
  ).pipe(
    Effect.provide(UsgsFeedLive.pipe(Layer.provide(FetchHttpClient.layer)))
  )
);

To run it on an instance, call the earthquakes Release with the client, HTTPS or MCP (Calling your Scraper).

Tests ​

The acceptance test runs the Scraper through ScraperTest.run against a FakeSite, without live network access. It generates whole feeds and every fault with it.effect.prop, and advances the test clock through Download's retries.

sh
pnpm --filter @scwrap/earthquakes test

kitchen-sink ​

PartValue
Package@scwrap/kitchen-sink
DefinitionKitchenSink in definition.ts
Input (KitchenSinkInput)checks: the checks to run, by name. Optional; without it every check but browser-use runs.
Output (CheckReport)One item per check, in the order below: check, capability, status (passed, failed or skipped), detail, durationMs
ErrorsRunTimeout
ImplementationKitchenSinkLive(providers) in kitchen-sink.ts. Requires HttpClient and ProxiedHttpClient; the browsers and the decision model are passed as Layers.
Releasekitchen-sink, a Worker release, revision v1
CheckCapabilityPasses when
settingsThe Scraper's settings and SCWRAP_RUN_IDSCWRAP_RUN_ID, CLOUDFLARE_ACCOUNT_ID and SCWRAP_CAPTCHA_GATEWAY_ID are set.
httpHttpClient, fetching directlyhttps://api.ipify.org/?format=json answers with an address.
proxyProxiedHttpClient through apifyProxy, grant proxy:apifyThe same request through the proxy answers with a different address.
captcha-templatesTextCaptchaSolver from @scwrap/captcha-templatesA glyph model trained on a sample captcha reads it back. Needs no network.
workers-aiDecisionModel Clef through AiGateway, grant ai:workers-aiClef answers for the sample captcha. Its reading is in detail; a wrong reading still passes, because the check is whether Workers AI answers.
browser-runBrowser through browserRun, grant browser:browser-runhttps://scwrap.dev/ opens with a 2xx status.
browser-useBrowser through browserUse, grant browser:browser-useThe same, in one Browser Use session with a 2-minute timeout. Browser Use bills each session, so it runs only when checks names it.

Each check runs on its own with a 90-second limit and becomes one item whatever happens, so a missing grant or a vendor outage shows as a failed item with the error in detail, and the Run still completes. Every check is also a KitchenSink.<check> span with kitchen_sink.status.

The instance must grant kitchen-sink its four capabilities and give it the settings of the workers-ai check:

sh
SCWRAP_INSTANCE_GRANTS='{"kitchen-sink": ["ai:workers-ai", "browser:browser-run", "browser:browser-use", "proxy:apify"]}'
json
{ "kitchen-sink": { "CLOUDFLARE_ACCOUNT_ID": "0123abcd", "SCWRAP_CAPTCHA_GATEWAY_ID": "scwrap-captcha" } }

The Release in instance-kitchen-sink.ts provides every provider:

ts
export default Deployment.worker({
  implementation: KitchenSinkLive({
    browserRun,
    browserUse: browserUseWith({ timeoutMinutes: 2 }),
    decisionModel: clef,
  }),
  module: import.meta.url,
  scraper: KitchenSink,
  services: Layer.mergeAll(FetchHttpClient.layer, apifyProxy),
});

Run every check but browser-use, or name the checks you want:

sh
curl -sS -X POST "$SCWRAP_INSTANCE_URL/scrapers/kitchen-sink/run" \
  -H "Authorization: Bearer $SCWRAP_INSTANCE_RUN_TOKEN" \
  -H 'content-type: application/json' \
  -d '{"checks": ["http", "proxy", "browser-use"]}'

CI runs it with the default checks after every production deploy and fails when a check fails (Shipping safely).