XPath Cheatsheet for Search Engine Optimisation (SEO)#
Certain XPath expressions are especially useful for search engine optimisation.
Content#
H1 Headline#
Count all <h1>
nodes to ensure that a web page has and only has one main headline. Should not be 0 or larger than 1:
Example
How to use Browserist to check whether a web page has exactly one <h1>
headline tag:
Image Alt Text#
Ensure that all images on web page have an alt text.
Example
How to use Browserist to check whether a web page has images without alt text:
Meta Data#
Similarly, ensure that a web page has meta description. Should not be 0 or larger than 1:
And you can ensure that length of the meta description is between 50 and 160 characters by using the string-length()
function:
string-length(/html/head/meta[@name='description']/@content) >= 50
string-length(/html/head/meta[@name='description']/@content) <= 160
Check if a web page has a canonical URL. If it has, it should only be 1:
Ensure that a web page has a robots meta tag. Should not be 0 or larger than 1:
Example
How to use Browserist to check whether a web page has relevant meta data:
Page Title#
Ensure that a web page doesn't have an empty title:
Example
How to use Browserist to check whether a web page has a page title:
Python | |
---|---|
Alternatively, there's a simpler solution without using XPath:
Python | |
---|---|