Question

I have the following code:

 foreach (HtmlNode link in doc.DocumentNode.SelectNodes("//a/@href[contains(., '/something/')]"))
             {
                 var content = link.OuterHtml;
                 // Then do something else
             }

content is equal to something like the following:

<a href="http://www.somelink.com">Happy Camper</a>

I would like content to equal just the URL portion of the HTML, so just this:

http://www.somelink.com

What would I need to change in my code to produce this desired result?

Was it helpful?

Solution

I figured it out. Just use:

var content = link.Attributes["href"].Value

Easy enough!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top