我有一个需要解析的HTML(如下所示)
<div id="mailbox" class="div-w div-m-0">
<h2 class="h-line">InBox</h2>
<div id="mailbox-table">
<table id="maillist">
<tr>
<th>From</th>
<th>Subject</th>
<th>Date</th>
</tr>
<tr onclick="location='readmail.html?mid=welcome'" style="font-weight: bold;">
<td>no-reply@somemail.net</td>
<td>
<a href="readmail.html?mid=welcome">Hi, Welcome</a>
</td>
<td>
<span title="2016-02-16 13:23:50 UTC">just now</span>
</td>
</tr>
<tr onclick="location='readmail.html?mid=T0wM6P'" style="font-weight: bold;">
<td>someone@outlook.com</td>
<td>
<a href="readmail.html?mid=T0wM6P">sa</a>
</td>
<td>
<span title="2016-02-16 13:24:04">just now</span>
</td>
</tr>
</table>
</div>
</div>
我需要解析 <tr onclick=
标签中的链接和 <td>
标签中的电子邮件地址。
到目前为止,我已经成功获取了html中第一个出现的电子邮件/链接。
HtmlDocument doc = new HtmlDocument();
doc.LoadHtml(responseFromServer);
有人能展示一下如何正确地完成吗?基本上我想要做的是从所述标签中提取所有电子邮件地址和链接。
foreach (HtmlNode link in doc.DocumentNode.SelectNodes("//tr[@onclick]"))
{
HtmlAttribute att = link.Attributes["onclick"];
Console.WriteLine(att.Value);
}
编辑:我需要将解析后的值以一对一的方式存储在一个类(列表)中。电子邮件(链接)和发件人电子邮件。
public class ClassMailBox
{
public string From { get; set; }
public string LinkToMail { get; set; }
}