我有这样的数据:
<tr class=hdr>
<th class="al cf">Name</th>
<th class="al">Type</th>
<th class="ar">Used Drive Space</th>
<th class="ar cl">Drive Size</th>
</tr>
<tr class="first o">
<td class="al cf">ITPHOFPWRFL01B E:\ Label:LotusDomino </td>
<td class="al">drive space</td>
<td class="ar">489.39106GB</td>
<td class="ar cl">549.9971GB</td>
</tr>
HTML文件中的那个文件,我想要读取这样的文件(比如在记事本中读取HTML文件),之后我想从那个first o
开始读取,我想得到的数据是{{1} }。我怎样才能获得数据?
答案 0 :(得分:0)
您应该使用像htmlagilitypack这样的html解析器。
您可以使用以下代码使用HtmlAgilityPack
using (OpenFileDialog openFileDialog = new OpenFileDialog())
{
openFileDialog.Filter = "HTML files|*.html;*.htm";
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.Load(openFileDialog.FileName);
foreach (var node in doc.DocumentNode.SelectNodes("//*[@class='first o']"))
{
foreach(var node2 in node.SelectNodes(".//td"))
{
txtContent.Text += node2.InnerHtml + " || ";
}
}
}
}