我正在为Html Agility Pack使用Fizzler。这是我的选择器,当我在firebug中测试jquery时,它工作得很好:
$('table.adsh>tbody:nth-child(1)>tr:nth-child(4) table tr:nth-child(1)>td:nth-child(2)')但是这一行代码在C#代码中返回null:
var item = page.QuerySelector("table.adsh>tbody:nth-child(1)>tr:nth-child(4) table tr:nth-child(1)>td:nth-child(2)");item始终为空。我的选择器有什么问题吗?
任何帮助都会提前表示感谢。
发布于 2014-04-12 20:32:51
我解决了这个问题。我打印出了page.QuerySelector("table.adsh").InnerHtml;,发现它没有包含任何tbody标记。但是当我在Chrome或FireFox中Inspect Element页面时,表格中包含了tbody标签。原因是原始的Html代码不包含tbody,并且当我对表执行Inspect Element操作时,浏览器会将tbody添加到检查过的代码中。在页面源代码中,我可以看到原始的html。
点击这里阅读更多内容:Why does firebug add to ?。
所以我从我的选择器中删除了tbody。
https://stackoverflow.com/questions/23029302
复制相似问题