Variable retrieval processor
Core v2.2.0
The
processor retrieves the value of a previously defined variable
and returns it for use in the current execution flow. It's commonly used to pass
data between different parts of a scraper configuration while preserving the original
Variable type (binary data, XML structure, lists).
<?xml version="1.0" encoding="UTF-8"?>
<config xmlns="http://org.webharvest/schema/2.1/core">
<def var="apiUrl" value="https://api.example.com"/>
<!-- Template syntax (simpler) -->
<http url="${apiUrl}/users"/>
<!-- Processor syntax (explicit) -->
<http>
<get-var var="apiUrl"/>/users
</http>
</config>
<?xml version="1.0" encoding="UTF-8"?>
<config xmlns="http://org.webharvest/schema/2.1/core">
<!-- Download image as binary -->
<def var="imageData">
<http url="https://example.com/logo.png"/>
</def>
<!-- CORRECT: get-var preserves byte[] array -->
<file path="logo.png" action="write" type="binary">
<get-var var="imageData"/>
</file>
<!-- WRONG: ${imageData} converts to String, corrupts binary! -->
<file path="broken.png" action="write" type="binary">
${imageData} <!-- ❌ Corrupted! -->
</file>
</config>
<?xml version="1.0" encoding="UTF-8"?>
<config xmlns="http://org.webharvest/schema/2.1/core">
<def var="xmlData">
<json-to-xml>
<http url="https://api.example.com/data.json"/>
</json-to-xml>
</def>
<!-- get-var preserves XML structure for XPath -->
<def var="username">
<xpath expression="//user/name/text()">
<get-var var="xmlData"/>
</xpath>
</def>
</config>
<?xml version="1.0" encoding="UTF-8"?>
<config xmlns="http://org.webharvest/schema/2.1/core">
<def var="productIds">
<xpath expression="//product/@id">
<html-to-xml>
<http url="https://example.com/products"/>
</html-to-xml>
</xpath>
</def>
<!-- Loop needs Variable object, not String -->
<loop item="id">
<get-var var="productIds"/>
<http url="https://example.com/product/${id}"/>
</loop>
</config>
<?xml version="1.0" encoding="UTF-8"?>
<config xmlns="http://org.webharvest/schema/2.1/core">
<def var="lang" value="en"/>
<def var="greeting_en" value="Hello"/>
<def var="greeting_pl" value="Cześć"/>
<def var="greeting_de" value="Hallo"/>
<!-- Dynamic variable name -->
<get-var var="greeting_${lang}"/>
<!-- Result: Hello (retrieves greeting_en) -->
</config>
<?xml version="1.0" encoding="UTF-8"?>
<config xmlns="http://org.webharvest/schema/2.1/core">
<!-- Fetch API data once -->
<def var="apiData">
<http url="https://api.example.com/data?key=${apiKey}"/>
</def>
<!-- Reuse the same response multiple times -->
<def var="userId">
<xpath expression="//user/@id">
<json-to-xml><get-var var="apiData"/></json-to-xml>
</xpath>
</def>
<def var="userName">
<xpath expression="//user/name">
<json-to-xml><get-var var="apiData"/></json-to-xml>
</xpath>
</def>
<def var="userEmail">
<xpath expression="//user/email">
<json-to-xml><get-var var="apiData"/></json-to-xml>
</xpath>
</def>
</config>
var
attribute itself supports ${} interpolation