我使用的是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])?
//他们现在还不支持
发布于 2016-03-02 16:42:15
\3A是编译时错误,因为\3不是C#字符串中的有效转义序列,因此需要转义反斜杠。使用\\:或\\3A都是正确的,但由于任何原因,选择器引擎似乎在使用CSS转义序列时遇到了问题。
看看是否可以使用属性选择器来解决这个问题,这样就完全不需要转义序列了:
HtmlNodeSelection.QuerySelectorAll(_htmlDocument.DocumentNode, "[id='unlocktheinbox:test']");https://stackoverflow.com/questions/35753051
复制相似问题