Ben
Ben

Reputation: 669

Grabbing just the URL of an href using HTMLAgilityPack

Here is the HTML source I'm trying to parse:

<a style='white-space: nowrap;' href='/AuthorStories-4931/dreamfall.htm'><img class='donoricon' alt='(Current Donor)'  title='(Current Donor)' src='http://static.tthf.me/images/donors/Current%20Donor.gif'/>dreamfall</a>

Here is the code I'm using:

authorLink = doc.DocumentNode.SelectSingleNode("//a[contains(@href, 'AuthorStories')]").OuterHtml;

This grabs the link correctly, but it also captures the img as well. The only part I want to grab is the href segment. Any suggestions on how to parse out just that particular section?

Upvotes: 0

Views: 843

Answers (1)

Rym
Rym

Reputation: 650

[Haven't touched HtmlAgilityPack in a few years, but this should be generally true]

Instead of taking OuterHtml, there should be an Attributes array on the node returned by SelectSingleNode, you should be able to get href from there.

Upvotes: 1

Related Questions