如何将一个CSSselect器转换为JavaScript中的XPath?

我正在寻找相当于Nokogiri :: CSS.xpath_for()。

我发现css2xpath但是Nokogiri的结果实际上工作,而css2xpath返回一个select器不。

我正在寻找的结果是这样的:=> [“// div [@id ='my_div'] // [position()= 1 and self :: table] // [position()= 1和self :: tbody] // [position()= 2 and self :: tr] // [position()= 1 and self :: td] // [position()= 1 and self :: table] // [position()= 1 and self :: tbody] // [position()= 2 and self :: tr] // [position()= 2 and self :: td]“]

我肯定会推荐使用库来将CSS转换为XPath。

例如,试试css-to-xpath