Where basic filters are based mainly on the type of node or its position in the result set, content filters are based on node value or surrounding hierarchical structure.
- a:contains(“About Us"); selects all a nodes where the node value contains the substring “About Us".
- img:empty selects all img nodes that contain no child nodes (including text nodes).
- li:has(a:contains(“About Us")) selects all li nodes that contain an a node with the substring “About Us" in its node value.
- li:parent selects all li nodes that contain child nodes (including text nodes).
Selector
|
CSS
|
XPath
|
nodes containing text
|
a:contains(“About Us")
|
//a[contains(text(), “About Us")]
|
nodes without children
|
img:empty
|
//img[not(node())]
|
nodes containing a selector match
|
li:has(a:contains (“About Us"))
|
//li//a[contains( text(), “About Us")]
|
nodes with children
|
li:parent
|
//li[node()
|
© CSS Selector Libraries — Web Scraping
>>> Back to TABLE OF CONTENTS <<< |