Html Agility Pack:查找注释节点 [英] Html Agility Pack: Find Comment Node
问题描述
基本上,我正在寻找XPATH \\div [@ class ='PricingInfo']
,但该div节点正在通过Javascript写入DOM。
因此,当我通过Html Agility包加载页面时,无法找到上面提到的XPATH。
事实证明,在某个特定脚本块我想解析。
<! - 模块328购买选项表 - >
< script type =text / javascriptlanguage =JavaScript>
var data = {
price:30.00
}
< / script>
对于这个网站,有很多脚本块,所以我需要通过查找来缩小范围这个自动生成的注释<! - 模块328买入选项表 - >
,并且该节点的同级将是正确的脚本块。
关于如何搜索特定评论然后获取相邻脚本块的任何想法?
谢谢! p>
htmlDoc.DocumentNode.SelectSingleNode(// comment()[contains(。,'购买选项')] / following-sibling :: script)
I am scraping a website that uses Javascript to dynamically populate the content of a website with the Html Agility pack.
Basically, I was searching for the XPATH "\\div[@class='PricingInfo']"
, but that div node was being written to the DOM via Javascript.
So, when I load the page through the Html Agility pack the XPATH mentioned above cannot be found.
It turns out there is a comment before a particular script block I want to parse.
<!--Module 328 Buying Options Table-->
<script type="text/javascript" language="JavaScript">
var data = {
price: 30.00
}
</script>
For this site, there are many script blocks and so I would need to narrow it down by the finding this auto-generated comment <!--Module 328 Buying Options Table-->
and the sibling of that node would be the correct script block.
Any idea on how I can search for a particular comment and then just get the adjacent script block?
Thank you!
htmlDoc.DocumentNode.SelectSingleNode("//comment()[contains(., 'Buying Options')]/following-sibling::script")
这篇关于Html Agility Pack:查找注释节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!