CSSSelectorConverter 1.2.3

CSSSelectorConverter 1.2.3

测试已测试
语言语言 Obj-CObjective C
许可证 MIT
发布最新发布2016年1月

Francis Chong 维护。



 
依赖
CocoaLumberjack~> 2.0.0
NUIParse>= 0
 

  • Francis Chong

CSS Selector Converter

Objective-C 的 CSS 选择器到 XPath 选择器的转换器。支持 CSS Selector Level 3 的主要子集。

我创建这个转换器是为了能够在 IGHTMLQuery 中使用 .class 代替 -hostAttribute contemplate(concat(' ', normalize-space(@class), ' ')) ' class

用法

#import "CSSSelectorConverter.h"

CSSSelectorToXPathConverter* converter = [[CSSSelectorToXPathConverter alloc] init];
[converter xpathWithCSS:@"p" error:nil];
// => "//p"

[converter xpathWithCSS:@"p.intro" error:nil];
// => "//p[contains(concat(' ', normalize-space(@class), ' '), ' intro ')]"

状态

它支持以下 CSS 选择器

*                                "//*"
p                                "//p"
p.intro                          "//p[contains(concat(' ', normalize-space(@class), ' '), ' intro ')]"
p#apple                          "//p[@id = 'apple']"
p *                              "//p//*"
p > *                            "//p/*"
H1 + P                           "//H1/following-sibling::*[1]/self::P"
H1 ~ P                           "//H1/following-sibling::P"
ul, ol                           "//ul | //ol"
p[align]                         "//p[@align]"
p[class~="intro"]                "//p[contains(concat(\" \", @class, \" \"),concat(\" \", 'intro', \" \"))]"
div[att|="val"]                  "//div[@att = \"val\" or starts-with(@att, concat(\"val\", '-'))]"

它支持以下伪类

  • first-child
  • last-child
  • first-of-type
  • last-of-type
  • only-child
  • only-of-type
  • empty

目前不支持带参数的伪类(我可能直到真正需要的时候才会实现它们)

  • nth-child()
  • nth-last-child()
  • nth-of-type()
  • nth-last-of-type()
  • not()

以下伪类将不支持

  • 动态伪类 (:link, :visited, :hover 等)
  • UI 元素状态伪类 (:enabled, :checked, :indeterminate)
  • :target
  • :lang
  • :root

开发

构建项目

  1. 安装 cocoapods
  2. 安装 pods: pod install

许可证

MIT 许可。参见 License.txt。