我能够将表中的所有数据都提取并扔到DataGrid视图中。现在我再次遇到了过滤相同信息的问题:红色,黄色,紫色,时间和名称。我在此摘录HTML,标题或Alt和href HOST = ...:
中发现了这些有趣的信息。<TD align=center><A
href="http://bb.intranet/cgi-bin/svcstatus.sh?HOST=RPRThostname&SERVICE=memory"><IMG
title=memory:yellow:13h02m border=0 alt=memory:yellow:13h02m
src="red%20%20Xymon%20-%20Status%20@%20Thu%20Jan%2003%20172037%202019_pliki/yellow-recent.gif"
width=16 height=16></A></TD>
我的代码将所有数据检索到表中。 Specialnie我将列的大小设置为23,因为该大小是整个HTML表的大小,
我想像上面写的那样扩展特定数据
HtmlAgilityPack.HtmlDocument d;
d = new HtmlAgilityPack.HtmlDocument();
d.LoadHtml(richTextBox1.Text);
var query = from table in d.DocumentNode.SelectNodes("//table").Cast<HtmlNode>()
from row in table.SelectNodes("//tr").Cast<HtmlNode>()
from cell in row.SelectNodes("//td").Cast<HtmlNode>() ///Cast<HtmlNode>() .First().Attributes["title"].Value.
select new { Table = table.Id, CellText = cell.OuterHtml };
foreach (var cell in query)
{
for (int i = 0; i < 27; i++)
{
this.dataGridView1.Columns.Add("col" + i.ToString(), "-");
}
int j = 0;
int counter = 0;
var values = new List<string>();
foreach (var cell in query)
{
if (j == 27)
{
this.dataGridView1.Rows.Add();
j = 0;
int k = 0;
foreach (DataGridViewCell dgcell in this.dataGridView1.Rows[counter].Cells)
{
//MessageBox.Show(values[k]);
dgcell.Value = values[k++];
}
counter++;
continue;
}
//DataRow r = dt.NewRow();
// int i = 0;
values.Add(cell.CellText);
j++;
}
}