Skip to content
Aravind Reddy V edited this page Jun 24, 2017 · 2 revisions

Osmosis depends on libxmljs for parsing documents and finding elements, however libxmljs only supports XPath selectors. Although XPath selectors have much more functionality than CSS selectors, they aren't as easy to read or write.

In order for Osmosis to support both CSS and XPath selectors, it has to convert CSS selectors into XPath selectors. Converting CSS selectors to XPath is beneficial because it allows Osmosis to supplement CSS functionality as well as support CSS selectors with XPath expressions in them.

CSS helpers

These CSS helper selectors are provided to simplify complex CSS expressions and to add jQuery-like functionality. Unlike normal pseudo-classes, these selectors can be chained any number of times in any order.

:first

Select first element (shortcut for :first-of-type)

:first(n), :limit(n)

Select first n elements

:last

Select last element (shortcut for :last-of-type)

:last(n)

Select last n elements

:skip(n), skip-first(n)

Skip first n elements

:skip-last(n)

Skip last n elements

:range(n1, n2)

Select n1 through n2 elements inclusive

:even

Select even elements

:odd

Select odd elements

:checked

Select nodes with checked or selected attributes

:has(selector)

Select elements that have at least one selector child

:before(selector)

Select elements that appear before selector

:before-sibling(selector)

Select siblings that appear before selector

:contains(string), :icontains(string)

Select elements whose contents contain string

:starts-with(string), :istarts-with(string)

Select elements whose contents start with string

:ends-with(string), :iends-with(string)

Select elements whose contents end with string

:internal, :external

Select nodes with internal or external hrefs or src

:http, :https, :javascript

Select nodes with a certain protocol

:domain(string)

Select nodes with a certain domain

:path(string)

Select nodes that start with a certain path

:html

Get element innerHTML

:source

Get element outerHTML

/comment()

Select comments

.exampleSelector[n]

Select nth element (shortcut for :nth-of-type)

@attribute

Select attribute