How to join values in XPath?

To join text in XPath the concat() function can be used. This is useful when parsing HTML for data values that are distributed through multiple elements or attributes.

See this interactive example:

<!-- select all product details as one string --> <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.

Question tagged: XPath

Related Posts

Ultimate XPath Cheatsheet for HTML Parsing in Web Scraping

Ultimate companion for HTML parsing using XPath selectors. This cheatsheet contains all syntax explanations with interactive examples.

Web Scraping With Ruby

Introduction to web scraping with Ruby. How to handle http connections, parse html files for data, best practices, tips and an example project.

Parsing HTML with Xpath

Introduction to xpath in the context of web-scraping. How to extract data from HTML documents using xpath, best practices and available tools.