My xpath is: /html/body/div/table/tbody/tr[2]/td[4]
I need to get an CSS to use it in jsoup selector.
I found a comparison between xpath and css
One should learn how to write css selectors, but a for a quick fix, try: cssify
For example, I put in your xpath and it spit out: html > body > div > table > tbody > tr:nth-of-type(2) > td:nth-of-type(4)
Try it out.
Are you looking for something like this:
http://jsfiddle.net/YZu8D/
.tablecont tr:nth-child(2) td:nth-child(4) {background-color: yellow; }
.tablecont tr:nth-child(3) td:nth-child(4) {background-color: yellow; }
While an expression like (//E)[2]
can't be represented with a CSS selector, an expression like E[2]
can be emulated using the :nth-of-type()
pseudo-class:
html > body > div > table > tbody > tr:nth-of-type(2) > td:nth-of-type(4)
Works good for me.
//Author: Oleksandr Knyga
function xPathToCss(xpath) {
return xpath
.replace(/\[(\d+?)\]/g, function(s,m1){ return '['+(m1-1)+']'; })
.replace(/\/{2}/g, '')
.replace(/\/+/g, ' > ')
.replace(/@/g, '')
.replace(/\[(\d+)\]/g, ':eq($1)')
.replace(/^\s+/, '');
}