theseer / css2xpath
PHP 库,将 CSS 选择器转换为 XPath
2.0.0
2019-08-28 04:35 UTC
Requires
- php: ^7.2|^8.0
This package is auto-updated.
Last update: 2024-08-28 15:25:00 UTC
README
这是一个将各种 CSS 选择器转换为等效 XPath 的库。
示例
$translator = new TheSeer\CSS2XPath\Translator(); // Will output //*[contains(concat(" ",normalize-space(@class)," ")," note ")] echo $translator->translate('.note'); // Will output //*[@id="me"] echo $translator->translate('#me');
安装
您可以使用 Composer 将此库作为本地、针对项目的依赖项添加到项目中
composer require theseer/css2xpath
支持的选择器
以下选择器目前得到支持
- #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]
- tag:enabled
- tag:checked
- tag:disabled
- :empty
- :root