小编Osc*_*edo的帖子

HtmlAgilityPack,使用XPath包含方法和谓词

HtmlAgilityPack,使用XPath包含方法

我正在使用HtmlAgilityPack,我需要知道一个类属性是否包含一个特定的单词,现在我有这个页面:

<div class="yom-mod yom-art-content "><div class="bd">
<p class="first"> ....................
  </p>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)

我这样做:

HtmlDocument doc2 = ...;
List<string> paragraphs = doc2.DocumentNode.SelectNodes("//div[@class = 'yom-mod yom-art-content ']//p").Select(paragraphNode => paragraphNode.InnerHtml).ToList();
Run Code Online (Sandbox Code Playgroud)

但它太具体了,我需要的是这样的:

List<string> paragraphs = doc2.DocumentNode.SelectNodes("//div[contains(@class, 'yom-art-content']//p").Select(paragraphNode => paragraphNode.InnerHtml).ToList();
Run Code Online (Sandbox Code Playgroud)

但它不起作用,请帮帮我..

xpath contains html-agility-pack

5
推荐指数
1
解决办法
9635
查看次数

标签 统计

contains ×1

html-agility-pack ×1

xpath ×1