XPath Cheatsheet for Links and URLs#
Combine attributes and functions to target specific link nodes. But first, how to get all <a>
link nodes:
Exact Matching#
Get all HTTPS links using the starts-with()
function:
Get all non-HTTPS links. As above, but negated by the non()
function:
Get all links for MP3 audio files using the ends-with()
function:
Get all links without a trailing slash by combining the not()
and ends-with()
functions.
Non-Exact Matching#
Get all blog links that using the contains()
function:
Negate the above to get all non-blog links using the not()
function:
Get all blog links about food using the and
operator:
Get all blog links that aren't about food by combining the and
and not()
operators:
Get all blog or news links using the or
operator:
Other#
Get all links with a URL longer than 55 characters using the string-length()
function: