Osc*_*edo 5 xpath contains html-agility-pack
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)
但它不起作用,请帮帮我..
JLR*_*she 16
也许问题只是你缺少contains()函数的右括号:
//div[contains(@class, 'yom-art-content']//p
v
//div[contains(@class, 'yom-art-content')]//p
List<string> paragraphs =
doc2.DocumentNode.SelectNodes("//div[contains(@class, 'yom-art-content')]//p")
.Select(paragraphNode => paragraphNode.InnerHtml).ToList();
Run Code Online (Sandbox Code Playgroud)
作为一般性建议,当您说出"它不起作用"之类的内容时,请解释您的意思.我怀疑您收到的错误消息可能有助于追踪问题?
| 归档时间: |
|
| 查看次数: |
9635 次 |
| 最近记录: |