简体   繁体   English

XPath到CSS选择器?

[英]XPath to CSS Selector?

How would you transform an xpath selector of the form: 您将如何转换形式的xpath选择器:

/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? 到css选择器等效吗?

Alternatively I'd need to generate a CSS selector for an HtmlAgilityPack.HtmlNode 另外,我需要为HtmlAgilityPack.HtmlNode生成CSS选择器

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: 我不知道为什么您绝对需要 CSS选择器(大多数(如果不是全部)HTML解析器和测试套件都支持CSS选择器 XPath),但是到底是什么呢:

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. 我只是不包括htmlbody伪类,因为它们是隐式的。

Are there no attributes (id or class) in any of these divs and tables? 这些div和表中是否没有属性(id或class)? If there are this makes the htmlagilitypack's job much easier. 如果存在,这将使htmlagilitypack的工作更加轻松。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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