A scrap is a script that reads a web page and returns its data as a list. This guide shows how to make one in the web app, write its script, and read how its runs went.
What is a scrap?
A scrap has three parts:
- Title & description: what the scrap is for.
- Workers: the browsers that run it (pick at least one).
- Request: a Puppeteer script that runs in the worker and hands back its data with
returnData(result).
Each run is kept in the scrap's Run tab with its status, time and result.
Make your first scrap
- In the web app, open Scraps and click New scrap.
- Fill in the title and description.
- Pick one or more workers in the Workers field.
- Click Create Scrap: you land in the scrap workspace.
- Open the Request tab and write your script.
A small script that reads the Hacker News titles, with the scrap's URL set to https://news.ycombinator.com/:
returnData(array) takes a list of objects: it is the result kept after each run.
var page = await browser.newPage();
await page.goto(TRAWL.url, { waitUntil: 'domcontentloaded' });
const result = await page.$$eval('span.titleline > a', els =>
els.map(el => ({ title: el.textContent.trim() }))
);
returnData(result);Extraction examples
Not sure what to write in What to extract? Take one of these:
- Extract all article titles and their links from the front page
- Track the price, stock status and rating of this product
- Get the 10 latest job listings with title, company and salary
- Collect the scores and dates of yesterday's games
- List the entries of the latest changelog release with their tags
- Turn the pricing table into rows of plan, monthly price and features
Variables in the script
Trawl gives the script a TRAWL object:
TRAWL.url: the URL set on the scrap. A call cannot change it.TRAWL.<name>: each parameter you set in Settings → Parameters. A parameter namedqueryisTRAWL.query. See Parameters.
The old @variable form (@url, @query) no longer works: always use TRAWL.*.
Run it
In the workspace, click Run (the green play button). The result shows up in the output panel and the run is added to the Run tab. To run it from your code, see Quickstart.
Read the status
Each run records a statusDetail:
statusDetail |
Meaning |
|---|---|
success |
The run returned at least one item, or the page said it has no results (see below) |
error |
The script threw an error: the output shows it |
empty |
The script ran but called returnData([]): the selector likely broke |
regression |
Far fewer items than the run before |
empty means the scrap needs a fix, not a success. Sites change their HTML: use Fix (see AI features) or update the selector.
A page with nothing to list is a success. When your script finds the site's own « no results » element (.no-results, #noResults, .empty-state, .nothing-found…) and calls returnData([]), the run is a success with 0 items and no fix starts. An empty list without that element stays empty.
Every field of a run: Results & payload.
if (await page.$('.no-results')) { returnData([]); return; }Versions
Each time you save the request or the parameters, Trawl keeps a version. Open the Versions tab to:
- See every change with its author and time.
- Show Diff: compare a version with the one before.
- Rollback: go back to any version (this adds a new version tagged
rollback).
You can add a message when you save, to say what changed.
Once it runs
- Run it on a schedule: Scheduling
- Get an email on a failure, or the results by email: Notifications
- Let the AI fix a broken script, or sum up each run: AI features
See also: Advanced scraping · Parameters
Next step → Advanced scraping