Is there a Python library that can parse an CSS selector and emit an equivalent XPath expression? For Ruby, there is Nokogiri.
2 Answers
I recently took over cssselect and made it an independent project after extracting it from lxml: http://packages.python.org/cssselect/
It does precisely what the question asks for. The XPath expressions produced can then be used in lxml. PyQuery actually uses cssselect (formerly lxml.cssselect)
4 Comments
Niklas B.
Wow, nice, thanks for the follow-up. So
lxml.cssselect.css_to_xpath is obsolete? Was it ever an official feature? Nice work indeed.Simon Sapin
@NiklasB. it was an implementation detail and will go away with lxml 2.4 (not released yet) when
lxml.cssselect becomes a thin wrapper around cssselect. The CSSSelector class and HtmlElement.cssselect method remain for compatibilityAlkanshel
I really wish lxml updated their docs often enough to mention that cssselect was taken out despite previously being packaged. but thanks
Simon Sapin
@Amalgovinus, file a bug?
How about pyQuery?
Answer based on PHP equivalent of PyQuery or Nokogiri?
1 Comment
Niklas B.
I don't see how this answers my question, and the documentation is not the best I've seen. Can you point me to the functionality that I am looking for? (Converting CSS to XPath, that is). EDIT found it! It's actually part of lxml though, but thanks for the hint.