The CSS selector should return only the first link, the one with the not-empty `span.string` sibling.
In jQuery this selector works well:
$('li:has(span.string:not(:empty))>h1>a')
but not in Nokogiri:
Nokogiri::HTML(html_source).css('li:has(span.string:not(:empty))>h1>a')
`:not` and `:empty` works well, but not `:has`.
---
1. Is there any documentation for CSS selectors in Nokogiri?
2. Maybe someone can write a custom `:has` pseudo class? Here is an [example][3] how to write a `:regexp` selector.
3. Optionally I can use XPath. How do I write XPath for `li:has(span.string:not(:empty))>h1>a`?
[1]: http://nokogiri.org/Nokogiri/XML/Node.html
[2]: http://api.jquery.com/has-selector/
[3]: http://nokogiri.org/Nokogiri/XML/Node.html#method-i-css :has pseudo is a jQuery extension, so I guess that Nokogiri does not support it because it's not part of any standard.
以上就是:has CSS pseudo class in Nokogiri的详细内容,更多请关注web前端其它相关文章!