π Structured Output
Fuyu lets your scripts export data using the record()
command. This output is stored in a structured format and can be downloaded or accessed via API.
π§© record(key, value)
β
Use record()
to capture key-value pairs during your script run:
title = get_title()
record("page_title", title)
Each time you call record()
with a previously unseen key, it adds that key to the current row.
When all keys have been seen at least once and you begin recording a key from the beginning again (e.g. record("x", ...)
after already recording "x"
), a new row is started. In this way, Fuyu groups values into table-like rows automatically.
π Multiple Output Rowsβ
To produce multiple output rows, use record()
in a loop and repeat the same keys per iteration:
items = find_elements(".product")
for item in items
name = item.text
link = item.href
record("name", name)
record("link", link)
end
Each group of repeated keys (name
, link
) will form a new row in the final structured output.
If you mix keys in an inconsistent order or omit them mid-way, the resulting JSON may look like:
[
{ "x": "1", "y": "0" },
{ "x": "2" }
]
So, for clean tabular output (e.g. CSV), keep key names and order consistent across rows.
π€ Exporting Dataβ
After a job completes, you can:
- View the results at the bottom of the Job Details page
- Download as
.csv
or.json
- Fetch from the API endpoint:
GET /api/scripts/:id/results
(replace:id
with your script's ID β requires authentication)
Each job contributes to the latest result set of the script.
π Best Practicesβ
- Use consistent key names across your script to keep output structured
- Donβt try to use
record()
for debugging β useprint()
instead - Avoid recording sensitive data like passwords or session tokens