简体   繁体   中英

XPath to CSS Selector?

How would you transform an xpath selector of the form:

/html[1]/body[1]/table[1]/tr[3]/td[1]/table[1]/tr[1]/td[2]/table[1]/tr[1]/td[2]

To it's css selector equivalent?

Alternatively I'd need to generate a CSS selector for an HtmlAgilityPack.HtmlNode

I don't know why you absolutely need a CSS selector (most if not all HTML parsers and test suites support both CSS selectors and XPath), but what the heck:

html > body > table:nth-child(1) > tr:nth-child(3) > td:nth-child(1) > table:nth-child(1) > tr:nth-child(1) > td:nth-child(2) > table:nth-child(1) > tr:nth-child(1) > td:nth-child(2)

I'm only not including pseudo-classes for html and body because they're implied.

Are there no attributes (id or class) in any of these divs and tables? If there are this makes the htmlagilitypack's job much easier.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM