- An initializer,
- A schema, and
- A response handler
Initializer
The initializer instructs the crawler where to start crawling. Each crawl run starts from an empty queue, so the initializer provides the first set of URLs for the run. It returns an array of URLs.Schema
The schema of a crawler on Crawlspace is responsible for setting column types and constraints for your crawler’s SQLite table. Return a Zod object in theschema() function to define your schema. Here’s an example:
Response handler
The response handler is the meat and potatoes of your crawler. Here you write custom logic to do whatever you’d like! Below is an example that scrapes data and inserts it into SQLite.Remember: by the time the handler runs, the request has already been made.
Use the handler to process the page’s DOM rather than fetch new requests.
Usage with Git
Use Git to version control your crawler. It’s recommended to put all of your crawlers into a single Git repo, rather than create a Git repo for each crawler. In other words, you will have a better experience if your.git directory is a sibling to the crawlspace.toml file.
You can also split up your crawler into multiple files if it starts to grow unwieldily —
just make sure that the initializer, schema, and response handler are exported as the default object
of the entry file.