edwinhuish/css-to-xpath

CssToXpath:轻松将 jQuery / CSS 选择器转换为 Xpath

v1.0.5 2020-04-16 09:06 UTC

This package is auto-updated.

Last update: 2024-09-16 19:41:12 UTC


README

这是一个库,可以将各种 CSS 选择器转换为它们的 Xpath 等价物。

示例

// Will output //*[contains(concat(' ', normalize-space(@class), ' '), ' node ')]
echo CssToXpath::transform('.node');

// Will output //*[@id='someid']
echo $translator->translate('#someid');

安装

您可以使用 Composer 将此库作为本地、按项目依赖项添加到您的项目中

composer require edwinhuish/css-to-xpath

支持的选择器

以下选择器目前得到支持

  • #id
  • tag#id
  • tag #id
  • tag
  • tag tag
  • tag > tag
  • tag + tag
  • tag ~ tag
  • tag, tag
  • .classname
  • tag.classname
  • tag .classname
  • tag.classname, tag.classname
  • tag.classname tag.classname
  • tag.classname > tag.classname
  • tag#id + tag > tag
  • tag[id]:contains(选择器)
  • tag[attribute][attribute]
  • tag[attribute]
  • tag[attribute=example]
  • tag[attribute^=exa]
  • tag[class$=mple]
  • tag[attribute*=e]
  • tag[attribute|=dialog]
  • tag[attribute!=made_up]
  • tag[attribute!="made_up"]
  • tag[attribute~=example]
  • tag:not(.classname)
  • tag:contains(selectors)
  • tag:nth-child(n)
  • tag:nth-child(even)
  • tag:nth-child(odd)
  • tag:nth-child(3n+8)
  • tag:nth-child(2n+1)
  • tag:nth-child(3)
  • tag:nth-child(4n)
  • tag:only-child
  • tag:last-child
  • tag:first-child
  • foo|bar
  • tag[attribute^=exa][attribute$=mple]
  • :empty
  • :root
  • :even
  • :odd
  • :first-child
  • :last-child
  • :only-child
  • :parent
  • :first
  • :last
  • :header
  • :not(foo)
  • :has(foo)
  • :contains(foo)

jQuery 选择器支持

  • :eq(2)
  • :eq(-5)
  • :gt(4)
  • :lt(8)