2016-03-02 77 views
0

我正在使用HTMLAgilityPack,并试图选择一个冒号的元素ID。Fizzler HTMLAgilityPack c#CSS选择器与冒号

Using Fizzler.Systems.HtmlAgilityPack; 

测试#1(未知伪类)

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

测试#2

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

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

(在位置16的无效字符)
HtmlNodeSelection.QuerySelectorAll(_htmlDocument.DocumentNode,"#unlocktheinbox\3A test"); 

测试#4(无效字符a t位置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])? 
// 

它们不支持它尚未:(

+0

你的第二和第四个方法都正确。我不知道他们为什么会失败。 – BoltClock

+0

我同意,我认为第2次和第4次尝试也是正确的,但它不适用于HTMLAgilityPack。 – Henry

回答

0

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

看看你是否能解决此同一个属性选择器来代替,这消除了完全转义序列的需求:

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