bevacqua
bevacqua

Reputation: 48476

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

Upvotes: 0

Views: 657

Answers (2)

Lakis
Lakis

Reputation: 299

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.

Upvotes: 0

BoltClock
BoltClock

Reputation: 723468

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.

Upvotes: 1

Related Questions