Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert CSS selector to XPath in Python

Is there a Python library that can parse an CSS selector and emit an equivalent XPath expression? For Ruby, there is Nokogiri.

like image 322
Niklas B. Avatar asked Sep 04 '25 17:09

Niklas B.


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)

like image 138
Simon Sapin Avatar answered Sep 06 '25 14:09

Simon Sapin


How about pyQuery?

Answer based on PHP equivalent of PyQuery or Nokogiri?

like image 21
kojiro Avatar answered Sep 06 '25 12:09

kojiro