HtmlAgilityPack, using XPath contains method
I'm using HtmlAgilityPack and i need to know if a class attribute contains a specific word, now i have this page:
<div class="yom-mod yom-art-content "><div class="bd">
<p class="first"> ....................
</p>
</div>
</div>
I'm doing this:
HtmlDocument doc2 = ...;
List<string> paragraphs = doc2.DocumentNode.SelectNodes("//div[@class = 'yom-mod yom-art-content ']//p").Select(paragraphNode => paragraphNode.InnerHtml).ToList();
But it's too much specific that I need is something like this:
List<string> paragraphs = doc2.DocumentNode.SelectNodes("//div[contains(@class, 'yom-art-content']//p").Select(paragraphNode => paragraphNode.InnerHtml).ToList();
But it don't work, please help me..
Perhaps the issue is simply that you're missing the closing parenthesis on the contains() function:
//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();
As a general suggestion, please explain what you mean when you say things like "it didn't work". I suspect you're getting an error message that might help track down the issue?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With