Block reference / Web interaction
Get text
Read the text of one element or many, and save it to the table or a variable.
Only in
WarpX Browser
Get text is the main way to scrape a page: point it at an element and it returns the text a person sees there. With Multiple on it reads every match, one row each, which is how you collect a list of names or prices. A regular expression, prefix and suffix let you trim or label the text as it is read.
Settings
- Element Selector
The element to act on, as a CSS selector or an XPath; anything starting with
/,(,@orid(is read as XPath, and it can hold a reference such as{{variables.selector}}. The crosshair button (Select an element) lets you pick the element in the profile's browser, including inside iframes and shadow roots, and the check button (Verify selector) tests what you typed.Example.product-card .price- Multiple
Reads every matching element instead of only the first. The result is a list, and each item becomes its own table row.
ExampleChecked- Mark elementwhen the selector is CSS
Tags every element the block acts on and skips tagged elements the next time this block runs, so inside a loop each run takes the next untouched match. Only offered for CSS selectors.
ExampleUnchecked- Wait for selector
Keeps looking for the element until it appears or Selector timeout (ms) runs out. Off, the element must already be on the page when the block runs, or the block fails.
ExampleChecked- Selector timeout (ms)when Wait for selector is on
How long Wait for selector keeps looking, in milliseconds. The default is
5000.Example8000- Regex
Keeps only the part of the text that matches this pattern; type it without the surrounding slashes. If nothing matches, the whole text is kept.
Example[0-9]+([.,][0-9]{2})?- Expression flags
Opened from the
/flagsbutton after Regex: global keeps every match, joined with spaces; ignore case and multiline work as in any regular expression. Without global, the first match and any bracketed groups are joined with spaces, so prefer(?:...)for groups you do not want repeated.Exampleglobal- Text prefix
Text added in front of every result, after Regex has been applied. It can hold a reference such as
{{variables.currency}}.ExampleUSD- Text suffix
Text added after every result, after Regex has been applied.
Example(list price)- Include HTML tags
Returns the element's full HTML, including the element itself, instead of its text. Takes precedence over Use textContent.
ExampleUnchecked- Use textContent
Returns all text inside the element, including hidden text and without the line breaks the page shows. Off, you get the text as displayed.
ExampleUnchecked- Assign to variable
Also stores the result in a workflow variable. With Multiple on, the variable holds the whole list.
ExampleChecked- Variable namewhen Assign to variable is on
The variable to write. Later blocks read it as
{{variables.prices}}; start the name with$push:to append to a list instead of replacing it.Exampleprices- Insert to table
Writes the result into the workflow's table. With Multiple on, each match becomes its own row, unless the column's type is array.
ExampleChecked- Select columnwhen Insert to table is on
The table column to write to. Later blocks read the first row as
{{table.price}}and the last as{{table.$last.price}}; if you pick none, the value goes into a column namedcolumn.Exampleprice- Add extra row
Writes a second, fixed value into another column next to every row this block inserts. Use it to label rows, for example with the search term they came from.
ExampleChecked- Valuewhen Add extra row is on
The value written into the extra column. It can hold a reference such as
{{variables.keyword}}.Example{{variables.keyword}}- Select columnwhen Add extra row is on
The column that receives the extra value.
Examplekeyword
Every block also has the shared block settings — a description, Disable block and what to do on an error, and Finding elements explains selectors in more depth. Fields that take text accept data from earlier blocks.
What it hands on
The text, or a list of texts with Multiple on. It goes to the chosen table column (one row per item) and, if ticked, to the variable. The block leaves by its single output; if no element matches, it fails.
Example: Collect product names and prices from a search results page
- Start
- New tab
- Get text
- Get text
- Add a New tab block that opens
https://shop.example.com/search?q={{variables.keyword}}. - Add a Get text block with Element Selector
.product-card h2, tick Multiple and Wait for selector, tick Insert to table and pick thenamecolumn. - Add a second Get text block with Element Selector
.product-card .priceand tick Multiple. - In the second block set Regex to
[0-9]+([.,][0-9]{2})?so only the number is kept, then tick Insert to table and pick thepricecolumn. - Tick Add extra row, set Value to
{{variables.keyword}}and pick thekeywordcolumn, so every row records the search it came from. - Run the workflow; the table has one row per product with
name,priceandkeyword.
Good to know
- If no element matches, the block fails with an element-not-found error and the workflow stops. To carry on instead, set On error in the block's settings to Continue flow or Execute fallback.
- Rows are filled column by column: the first Get text fills
namedown the rows, the second fillspricefrom the top again. Both selectors must match the same number of elements in the same order, or the columns will not line up. - Get text reads what is on the page now. On a page that loads more items as you scroll, run Scroll element first.
See also
- Attribute value — Read or set an HTML attribute on an element, such as a link's
hrefor an image'ssrc. - Loop elements — Run the blocks after it once for each element that matches a selector, loading more as it goes.
- RegEx variable — Replace a text variable with what a regular expression matches, or with a replaced version.