HtmlDocumentdoc=newHtmlDocument();
doc.LoadHtml(responseFromServer);
foreach (HtmlNode link in doc.DocumentNode.SelectNodes("//tr[@onclick]"))
{
HtmlAttributeatt= link.Attributes["onclick"];
ClassMailBoxclassMailbox=newClassMailBox() { LinkToMail = att.Value };
classMailBoxes.Add(classMailbox);
}
intcurrentPosition=0;
foreach (HtmlNode tableDef in doc.DocumentNode.SelectNodes("//tr[@onclick]/td[1]"))
{
classMailBoxes[currentPosition].From = tableDef.InnerText;
currentPosition++;
}
To keep this code simple, I'm assuming some things:
The email is always on the first td inside the tr which contains an onlink property
Every tr with an onlink attribute contains an email
If those conditions don't apply this code won't work and it could throw some exceptions (IndexOutOfRangeExceptions) or it could match links with wrong email addresses.
Post a Comment for "Parsing Html Using Agility Pack"