<exit>

Exit/termination processor

Core v2.2.0

Overview

The processor immediately terminates scraper execution, optionally with a custom message. It's useful for early termination on errors, completion conditions, or when specific data is found.

Usage Examples

Example 1: Exit on error

example-1.xml
<?xml version="1.0" encoding="UTF-8"?>
<config xmlns="http://org.webharvest/schema/2.1/core">
<def var="response">
  <http url="https://api.example.com/data"/>
</def>

<if condition="${empty(response)}">
  <exit message="API returned empty response - terminating"/>
</if>
</config>

Example 2: Exit when target found

example-2.xml
<?xml version="1.0" encoding="UTF-8"?>
<config xmlns="http://org.webharvest/schema/2.1/core">
<loop item="item" maxloops="1000">
  <xpath expression="//item">...</xpath>
  
  <if condition="${item == 'TARGET'}">
    <file path="found.txt" action="write">Found target: ${item}</file>
    <exit message="Target item found, stopping search"/>
  </if>
</loop>
</config>

Example 3: Conditional exit based on quota

example-3.xml
<?xml version="1.0" encoding="UTF-8"?>
<config xmlns="http://org.webharvest/schema/2.1/core">
<def var="requestCount" value="0"/>

<while condition="${hasMore}">
  <http url="https://api.example.com/data"/>
  
  <def var="requestCount">
    <script>parseInt(context.getVar("requestCount")) + 1</script>
  </def>
  
  <if condition="${requestCount >= 100}">
    <exit message="Request quota reached (100 requests)"/>
  </if>
</while>
</config>

Parameters

Important Notes

Related Processors