Moshi
Moshi

Reputation: 1423

Select value of tag in HTML with Microsoft Agility Pack

I have html code with this element.

<span itemprop="datePublished" content="2016-06-18T00:44:00+06:00">০০:৪৫, জুন ১৮, ২০১৬</span>

With Agility Pack I want value "2016-06-18T00:44:00+06:00" of Attribute content. I can select InnerText with this code:

HtmlDocument.DocumentNode.SelectSingleNode("//span[@itemprop='datePublished']");

Upvotes: 0

Views: 45

Answers (1)

har07
har07

Reputation: 89285

Use GetAttributeValue(attrName, defaultVal) method which return attribute value of name attrName if it exists, and return defaultVal otherwise :

var span = HtmlDocument.DocumentNode.SelectSingleNode("//span[@itemprop='datePublished']");
var content = span.GetAttributeValue("content", "");

Upvotes: 1

Related Questions