🚀 We are hiring! See open positions

How to join values using XPath concat?

by scrapecrow Apr 19, 2023

The concat() function is an XPath expression is a string join function for multiple string values. It's useful when parsing an HTML document for a specific string through distributed multiple elements or attributes:

For example, let's see the below interactive XPath expression evaluation:

<html> <div> <h2>Coffee</h2> <span data-currency="USD">4.69</span> </div> </html>

Above, we contact the name and price elements into a single string. However, we can join any number of elements. Here's an example through two or more arguments:

<html> <div> <h2>Coffee</h2> <span data-currency="USD">4.69</span> </div></html>

Note that concat() only works with strings so it'll automatically try convert elements to their text() values. For further details on XPath selectors, including common tips and tricks, refer to our dedicated guide.

Related Articles