Thursday, 5 September 2013

select next element html Agility pack C#

select next element html Agility pack C#

I am using htmlagilitypack and reinerating through div class="fileHeader"
searching for string RelayClinical Patient Education with Animations
Install zip inside h4 element. Once found i want to capture the "href"
inside the anchor tag of that particular block. Please help.
HTML Source
<div class="fileHeader" id="fileHeader_7311111">
<h4 class="collapsed">RelayClinical Patient Education with Animations
Install zip</h4>
<div class="defaultMethod">
<a class="buttonGrey"
href="https://mckc-esd.subscribenet.com/cgi-bin/download?rid=2511740931&amp;rp=DTM20130905162949MzcyODIwNjM0"
title="Clicking this link will open a new window."
rel="noreferrer">
HTTPS Download
</a>
</div>
</div>
C#
HtmlNodeCollection fileHeaderNodes =
bodyNode.SelectNodes("//div[@class='fileHeader']//h4");
foreach (HtmlNode fileHeader in fileHeaderNodes)
{
if (fileHeader.InnerText.Trim() == "RelayClinical Patient Education
with Animations Install zip")
{
HtmlNodeCollection fileHeaderNodes =
bodyNode.SelectNodes("//div[@class='fileHeader']//h4");
foreach (HtmlNode fileHeader in fileHeaderNodes)
{
if (fileHeader.InnerText.Trim() == "RelayClinical
Patient Education with Animations Install zip")
{
foreach (HtmlNode link in
fileHeader.SelectNodes("//a[@href]"))
{
// extract the link and put in dataUrl var
if ((link.InnerText.Trim() == "HTTPS
Download") && isFound == true)
{
count++;
// select all a tags (html anchor
tags) that have a href attribute
HtmlAttribute att =
link.Attributes["href"];
dataUrl = att.Value;
}
}
}
}
}
}

No comments:

Post a Comment