Fizzler HTMLAgilityPack c# CSS Selector with Colon

本文关键字:with Colon Selector CSS HTMLAgilityPack Fizzler | 更新日期: 2023-09-27 18:37:07

我正在使用HTMLAgilityPack,我正在尝试选择一个带有冒号的元素ID。

Using Fizzler.Systems.HtmlAgilityPack;

测试 #1(未知伪类)

HtmlNodeSelection.QuerySelectorAll( _htmlDocument.DocumentNode,"#unlocktheinbox:test");

测试 #2(位置 16 处的字符无效。

HtmlNodeSelection.QuerySelectorAll( _htmlDocument.DocumentNode,"#unlocktheinbox'':test");

测试 #3(无法识别的转义序列)

HtmlNodeSelection.QuerySelectorAll( _htmlDocument.DocumentNode,"#unlocktheinbox'3A test");

测试 #4(位置 16 处的字符无效。

HtmlNodeSelection.QuerySelectorAll( _htmlDocument.DocumentNode,"#unlocktheinbox''3A test");

我做错了什么?

原来我看了Fizzler的源代码。

 // TODO Support full string syntax!
 //
 // string    {string1}|{string2}
 // string1   '"([^'n'r'f''"]|''{nl}|{nonascii}|{escape})*'"
 // string2   ''([^'n'r'f''']|''{nl}|{nonascii}|{escape})*''
 // nonascii  [^'0-'177]
 // escape    {unicode}|''[^'n'r'f0-9a-f]
 // unicode   ''[0-9a-f]{1,6}('r'n|[ 'n'r't'f])?
 //

他们还不支持它:(

Fizzler HTMLAgilityPack c# CSS Selector with Colon

'3A是编译时错误'3因为 C# 字符串中不是有效的转义序列,因此需要转义反斜杠。使用 '':''3A 是正确的,但无论出于何种原因,选择器引擎似乎在 CSS 转义序列方面遇到了问题。

看看是否可以使用属性选择器来解决此问题,这完全消除了对转义序列的需求:

HtmlNodeSelection.QuerySelectorAll(_htmlDocument.DocumentNode, "[id='unlocktheinbox:test']");