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.
To select sibling elements in XPath the preceding-sibling
and following-sibling
axes can be used - see these interactive examples:
preceding-sibling::span
will select any siblings that precede (i.e. are above) the current element:following-sibling::span
will select siblings that follow (i.e. are below) the current element:Note that the wildcard character can be used instead of explicit element names (e.g. following-sibling::*
) to select siblings of any element name.
For more on XPath, see our full introduction article