Как захватить HTML элемент и поместить его в datagridview
Дорогие,
Не могли бы вы мне помочь?
У меня есть проблема с HTML-таблицей захватить только красные и желтые оповещения и поместить в DataGridView. Сначала я попытался захватить определенный предмет с помощью пакета Htmlaiglity, но это тоже не сработало. Ниже я отправляю HTML-код и код C#
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <!-- saved from url=(0053)http://bb.intranet/bb/alert.html --> <HTML><HEAD><META content="IE=7.0000" http-equiv="X-UA-Compatible"> <TITLE>red : Xymon - Status @ Thu Jan 03 17:20:37 2019</TITLE> <META content="text/html; charset=utf-8" http-equiv=Content-Type> <META content=60 http-equiv=REFRESH> <META content="Sat, 01 Jan 2001 00:00:00 GMT" http-equiv=EXPIRES><!-- Styles for the Xymon body --><LINK rel=stylesheet type=text/css href="red%20%20Xymon%20-%20Status%20@%20Thu%20Jan%2003%20172037%202019_pliki/xymonbody.css"><!-- Styles for the menu bar --><LINK rel=stylesheet type=text/css href="red%20%20Xymon%20-%20Status%20@%20Thu%20Jan%2003%20172037%202019_pliki/xymonmenu-blue.css"><!-- The favicon image --><LINK rel="shortcut icon" href="/bb/gifs/favicon-red.ico"> <META name=GENERATOR content="MSHTML 11.00.9600.19230"></HEAD> <TBODY> <TR> <TD height=16> </TD></TR><!-- For the menu bar --> <TR> <TD vAlign=middle width="30%" align=left><FONT color=silver size=+1 face="Arial, Helvetica">Xymon</FONT> </TD> <TD vAlign=middle width="40%" align=center> <CENTER><FONT color=silver size=+1 face="Arial, Helvetica">Current <FONT color=yellow>ALERT</FONT> Systems </FONT></CENTER></TD> <TD vAlign=middle width="30%" align=right><FONT color=silver size=+1 face="Arial, Helvetica">Thu Jan 3 17:21:26 CET 2019 </FONT></TD></TR> <TR> <TD colSpan=3> <TABLE align=center summary="Xymon status icons" border=1> <TBODY> <TR> <TH vAlign=top align=left>Color</TH> <TD>Recently changed</TD> <TD>Last change > 24 hours</TD></TR> <TR> <TH vAlign=top align=left>Green: Status is OK</TH> <TD align=center><IMG alt="Green - recently changed" src="red%20%20Xymon%20-%20Status%20@%20Thu%20Jan%2003%20172037%202019_pliki/green-recent.gif"></TD> <TD align=center><IMG alt=Green src="red%20%20Xymon%20-%20Status%20@%20Thu%20Jan%2003%20172037%202019_pliki/green.gif"></TD></TR> <TR> <TH vAlign=top align=left>Yellow: Warning</TH> <TD align=center><IMG alt="Yellow - recently changed" src="red%20%20Xymon%20-%20Status%20@%20Thu%20Jan%2003%20172037%202019_pliki/yellow-recent.gif"></TD> <TD align=center><IMG alt=Yellow src="red%20%20Xymon%20-%20Status%20@%20Thu%20Jan%2003%20172037%202019_pliki/yellow.gif"></TD></TR> <TR> <TH vAlign=top align=left>Red: Critical</TH> <TD align=center><IMG alt="Red - recently changed" src="red%20%20Xymon%20-%20Status%20@%20Thu%20Jan%2003%20172037%202019_pliki/red-recent.gif"></TD> <TD align=center><IMG alt=Red src="red%20%20Xymon%20-%20Status%20@%20Thu%20Jan%2003%20172037%202019_pliki/red.gif"></TD></TR> <TR> <TH vAlign=top align=left>Clear: No data</TH> <TD align=center><IMG alt="Clear - recently changed" src="red%20%20Xymon%20-%20Status%20@%20Thu%20Jan%2003%20172037%202019_pliki/clear-recent.gif"></TD> <TD align=center><IMG alt=Clear src="red%20%20Xymon%20-%20Status%20@%20Thu%20Jan%2003%20172037%202019_pliki/clear.gif"></TD></TR> <TR> <TH vAlign=top align=left>Purple: No report</TH> <TD align=center><IMG alt="Purple - recently changed" src="red%20%20Xymon%20-%20Status%20@%20Thu%20Jan%2003%20172037%202019_pliki/purple-recent.gif"></TD> <TD align=center><IMG alt=Purple src="red%20%20Xymon%20-%20Status%20@%20Thu%20Jan%2003%20172037%202019_pliki/purple.gif"></TD></TR> <TR> <TH vAlign=top align=left>Blue: Disabled</TH> <TD align=center><IMG alt="Blue - recently changed" src="red%20%20Xymon%20-%20Status%20@%20Thu%20Jan%2003%20172037%202019_pliki/blue-recent.gif"></TD> <TD align=center><IMG alt=Blue src="red%20%20Xymon%20-%20Status%20@%20Thu%20Jan%2003%20172037%202019_pliki/blue.gif"></TD></TR></TBODY></TABLE><BR> <HR width="100%"> </TD></TR></TBODY></TABLE><BR> <CENTER> <TABLE cellPadding=2 summary="Group Block" border=0> <TBODY> <TR> <TD vAlign=middle> <CENTER><FONT color=#fffff0 size=+1></FONT> </CENTER></TD> <TD vAlign=bottom width=45 align=center><A href="http://bb.intranet/cgi-bin/columndoc.sh?FicExist"><FONT color=#87a9e5 size=-1>FicExist</FONT></A> </TD> <TD vAlign=bottom width=45 align=center><A href="http://bb.intranet/cgi-bin/columndoc.sh?JobsLogs-Httpd"><FONT color=#87a9e5 size=-1>JobsLogs-Httpd</FONT></A> </TD> <TD vAlign=bottom width=45 align=center><A href="http://bb.intranet/cgi-bin/columndoc.sh?JobsLogs-Jboss"><FONT color=#87a9e5 size=-1>JobsLogs-Jboss</FONT></A> </TD> <TD vAlign=bottom width=45 align=center><A href="http://bb.intranet/cgi-bin/columndoc.sh?JobsLogs-Tomcat"><FONT color=#87a9e5 size=-1>JobsLogs-Tomcat</FONT></A> </TD> <TD vAlign=bottom width=45 align=center><A href="http://bb.intranet/cgi-bin/columndoc.sh?bbinfos"><FONT color=#87a9e5 size=-1>bbinfos</FONT></A> </TD> <TD vAlign=bottom width=45 align=center><A href="http://bb.intranet/cgi-bin/columndoc.sh?certExp"><FONT color=#87a9e5 size=-1>certExp</FONT></A> </TD> <TD vAlign=bottom width=45 align=center><A href="http://bb.intranet/cgi-bin/columndoc.sh?conn"><FONT color=#87a9e5 size=-1>conn</FONT></A> </TD> <TD vAlign=bottom width=45 align=center><A href="http://bb.intranet/cgi-bin/columndoc.sh?cpu"><FONT color=#87a9e5 size=-1>cpu</FONT></A> </TD> <TD vAlign=bottom width=45 align=center><A href="http://bb.intranet/cgi-bin/columndoc.sh?disk"><FONT color=#87a9e5 size=-1>disk</FONT></A> </TD> <TD vAlign=bottom width=45 align=center><A href="http://bb.intranet/cgi-bin/columndoc.sh?holdmgr"><FONT color=#87a9e5 size=-1>holdmgr</FONT></A> </TD> <TD vAlign=bottom width=45 align=center><A href="http://bb.intranet/cgi-bin/columndoc.sh?info"><FONT color=#87a9e5 size=-1>info</FONT></A> </TD> <TD vAlign=bottom width=45 align=center><A href="http://bb.intranet/cgi-bin/columndoc.sh?load"><FONT color=#87a9e5 size=-1>load</FONT></A> </TD> <TD vAlign=bottom width=45 align=center><A href="http://bb.intranet/cgi-bin/columndoc.sh?memory"><FONT color=#87a9e5 size=-1>memory</FONT></A> </TD> <TD vAlign=bottom width=45 align=center><A href="http://bb.intranet/cgi-bin/columndoc.sh?msgs"><FONT color=#87a9e5 size=-1>msgs</FONT></A> </TD> <TD vAlign=bottom width=45 align=center><A href="http://bb.intranet/cgi-bin/columndoc.sh?nfs"><FONT color=#87a9e5 size=-1>nfs</FONT></A> </TD> <TD vAlign=bottom width=45 align=center><A href="http://bb.intranet/cgi-bin/columndoc.sh?noimg"><FONT color=#87a9e5 size=-1>noimg</FONT></A> </TD> <TD vAlign=bottom width=45 align=center><A href="http://bb.intranet/cgi-bin/columndoc.sh?noroot"><FONT color=#87a9e5 size=-1>noroot</FONT></A> </TD> <TD vAlign=bottom width=45 align=center><A href="http://bb.intranet/cgi-bin/columndoc.sh?procs"><FONT color=#87a9e5 size=-1>procs</FONT></A> </TD> <TD vAlign=bottom width=45 align=center><A href="http://bb.intranet/cgi-bin/columndoc.sh?svcs"><FONT color=#87a9e5 size=-1>svcs</FONT></A> </TD> <TD vAlign=bottom width=45 align=center><A href="http://bb.intranet/cgi-bin/columndoc.sh?trends"><FONT color=#87a9e5 size=-1>trends</FONT></A> </TD> <TD vAlign=bottom width=45 align=center><A href="http://bb.intranet/cgi-bin/columndoc.sh?unibackup"><FONT color=#87a9e5 size=-1>unibackup</FONT></A> </TD></TR> <TR class=line> <TD noWrap align=left><A name=BFhostname> </A> <A href="http://bb.intranet/bb/NEWPROD/BCPPROD/BCPPROD.html"><FONT color=#ffffcc size=+1 face="Tahoma, Arial, Helvetica">BFhostname</FONT></A> <TD align=center>-</TD> <TD align=center>-</TD> <TD align=center>-</TD> <TD align=center>-</TD> <TD align=center>-</TD> <TD align=center>-</TD> <TD align=center><A href="http://bb.intranet/cgi-bin/svcstatus.sh?HOST=BFhostname&SERVICE=conn"><IMG title=conn:green:40d07h34m border=0 alt=conn:green:40d07h34m src="red%20%20Xymon%20-%20Status%20@%20Thu%20Jan%2003%20172037%202019_pliki/green.gif" width=16 height=16></A></TD> <TD align=center><A href="http://bb.intranet/cgi-bin/svcstatus.sh?HOST=BFhostname&SERVICE=cpu"><IMG title=cpu:green:40d05h39m border=0 alt=cpu:green:40d05h39m src="red%20%20Xymon%20-%20Status%20@%20Thu%20Jan%2003%20172037%202019_pliki/green.gif" width=16 height=16></A></TD> <TD align=center><A href="http://bb.intranet/cgi-bin/svcstatus.sh?HOST=BFhostname&SERVICE=disk"><IMG title=disk:red:9d13h24m border=0 alt=disk:red:9d13h24m src="red%20%20Xymon%20-%20Status%20@%20Thu%20Jan%2003%20172037%202019_pliki/red.gif" width=16 height=16></A></TD> <TD align=center>-</TD> <TD align=center><A href="http://bb.intranet/cgi-bin/svcstatus.sh?HOST=BFhostname&SERVICE=info"><IMG title=info:green:56.346.50.11 border=0 alt=info:green:56.346.50.11 src="red%20%20Xymon%20-%20Status%20@%20Thu%20Jan%2003%20172037%202019_pliki/green.gif" width=16 height=16></A></TD> <TD align=center>-</TD> <TD align=center><A href="http://bb.intranet/cgi-bin/svcstatus.sh?HOST=BFhostname&SERVICE=memory"><IMG title=memory:yellow:3d13h09m border=0 alt=memory:yellow:3d13h09m src="red%20%20Xymon%20-%20Status%20@%20Thu%20Jan%2003%20172037%202019_pliki/yellow.gif" width=16 height=16></A></TD> <TD align=center>-</TD> <TD align=center><A href="http://bb.intranet/cgi-bin/svcstatus.sh?HOST=BFhostname&SERVICE=nfs"><IMG title=nfs:green:40d06h39m border=0 alt=nfs:green:40d06h39m src="red%20%20Xymon%20-%20Status%20@%20Thu%20Jan%2003%20172037%202019_pliki/green.gif" width=16 height=16></A></TD> <TD align=center>-</TD> <TD align=center>-</TD> <TD align=center><A href="http://bb.intranet/cgi-bin/svcstatus.sh?HOST=BFhostname&SERVICE=procs"><IMG title=procs:red:6d02h34m border=0 alt=procs:red:6d02h34m src="red%20%20Xymon%20-%20Status%20@%20Thu%20Jan%2003%20172037%202019_pliki/red.gif" width=16 height=16></A></TD> <TD align=center>-</TD> <TD align=center><A href="http://bb.intranet/cgi-bin/svcstatus.sh?HOST=BFhostname&SERVICE=trends"><IMG title=trends:green:56.346.50.11 border=0 alt=trends:green:56.346.50.11 src="red%20%20Xymon%20-%20Status%20@%20Thu%20Jan%2003%20172037%202019_pliki/green.gif" width=16 height=16></A></TD> <TD align=center><A href="http://bb.intranet/cgi-bin/svcstatus.sh?HOST=BFhostname&SERVICE=unibackup"><IMG title=unibackup:red:33d05h19m border=0 alt=unibackup:red:33d05h19m src="red%20%20Xymon%20-%20Status%20@%20Thu%20Jan%2003%20172037%202019_pliki/red.gif" width=16 height=16></A></TD></TR><!-- DEBUG NAME=RPRThostname alert = 2--> <TR class=line> <TD noWrap align=left><A name=RPRThostname> </A> <A href="http://bb.intranet/bb/NEWPROD/BCPPROD/BCPPROD.html"><FONT color=#ffffcc size=+1 face="Tahoma, Arial, Helvetica">RPRThostname</FONT></A> <TD align=center>-</TD> <TD align=center>-</TD> <TD align=center>-</TD> <TD align=center>-</TD> <TD align=center>-</TD> <TD align=center>-</TD> <TD align=center><A href="http://bb.intranet/cgi-bin/svcstatus.sh?HOST=RPRThostname&SERVICE=conn"><IMG title=conn:green:39d11h20m border=0 alt=conn:green:39d11h20m src="red%20%20Xymon%20-%20Status%20@%20Thu%20Jan%2003%20172037%202019_pliki/green.gif" width=16 height=16></A></TD> <TD align=center><A href="http://bb.intranet/cgi-bin/svcstatus.sh?HOST=RPRThostname&SERVICE=cpu"><IMG title=cpu:green:39d09h47m border=0 alt=cpu:green:39d09h47m src="red%20%20Xymon%20-%20Status%20@%20Thu%20Jan%2003%20172037%202019_pliki/green.gif" width=16 height=16></A></TD> <TD align=center><A href="http://bb.intranet/cgi-bin/svcstatus.sh?HOST=RPRThostname&SERVICE=disk"><IMG title=disk:red:13h12m border=0 alt=disk:red:13h12m src="red%20%20Xymon%20-%20Status%20@%20Thu%20Jan%2003%20172037%202019_pliki/red-recent.gif" width=16 height=16></A></TD> <TD align=center>-</TD> <TD align=center><A href="http://bb.intranet/cgi-bin/svcstatus.sh?HOST=RPRThostname&SERVICE=info"><IMG title=info:green:56.346.50.12 border=0 alt=info:green:56.346.50.12 src="red%20%20Xymon%20-%20Status%20@%20Thu%20Jan%2003%20172037%202019_pliki/green.gif" width=16 height=16></A></TD> <TD align=center>-</TD> <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> <TD align=center>-</TD> <TD align=center><A href="http://bb.intranet/cgi-bin/svcstatus.sh?HOST=RPRThostname&SERVICE=nfs"><IMG title=nfs:green:17d02h57m border=0 alt=nfs:green:17d02h57m src="red%20%20Xymon%20-%20Status%20@%20Thu%20Jan%2003%20172037%202019_pliki/green.gif" width=16 height=16></A></TD> <TD align=center>-</TD> <TD align=center>-</TD> <TD align=center><A href="http://bb.intranet/cgi-bin/svcstatus.sh?HOST=RPRThostname&SERVICE=procs"><IMG title=procs:green:40d07h52m border=0 alt=procs:green:40d07h52m src="red%20%20Xymon%20-%20Status%20@%20Thu%20Jan%2003%20172037%202019_pliki/green.gif" width=16 height=16></A></TD> <TD align=center>-</TD> <TD align=center><A href="http://bb.intranet/cgi-bin/svcstatus.sh?HOST=RPRThostname&SERVICE=trends"><IMG title=trends:green:56.346.50.12 border=0 alt=trends:green:56.346.50.12 src="red%20%20Xymon%20-%20Status%20@%20Thu%20Jan%2003%20172037%202019_pliki/green.gif" width=16 height=16></A></TD> <TD align=center><A href="http://bb.intranet/cgi-bin/svcstatus.sh?HOST=RPRThostname&SERVICE=unibackup"><IMG title=unibackup:red:33d05h17m border=0 alt=unibackup:red:33d05h17m src="red%20%20Xymon%20-%20Status%20@%20Thu%20Jan%2003%20172037%202019_pliki/red.gif" width=16 height=16></A></TD></TR> <TR class=line> <TD noWrap align=left><A name=EvohostnameL> </A> <A href="http://bb.intranet/bb/NEWPROD/P_OPERATION/P_OPERATION.html"><FONT color=#ffffcc size=+1 face="Tahoma, Arial, Helvetica">EvohostnameL</FONT></A> <TD align=center>-</TD> <TD align=center>-</TD> <TD align=center>-</TD> <TD align=center>-</TD> <TD align=center><A href="http://bb.intranet/cgi-bin/svcstatus.sh?HOST=EvohostnameL&SERVICE=bbinfos"><IMG title=bbinfos:green:417d11h10m border=0 alt=bbinfos:green:417d11h10m src="red%20%20Xymon%20-%20Status%20@%20Thu%20Jan%2003%20172037%202019_pliki/green.gif" width=16 height=16></A></TD> <TD align=center>-</TD> <TD align=center><A href="http://bb.intranet/cgi-bin/svcstatus.sh?HOST=EvohostnameL&SERVICE=conn"><IMG title=conn:green:557d03h51m border=0 alt=conn:green:557d03h51m src="red%20%20Xymon%20-%20Status%20@%20Thu%20Jan%2003%20172037%202019_pliki/green.gif" width=16 height=16></A></TD> <TD align=center><A href="http://bb.intranet/cgi-bin/svcstatus.sh?HOST=EvohostnameL&SERVICE=cpu"><IMG title=cpu:green:3d04h09m border=0 alt=cpu:green:3d04h09m src="red%20%20Xymon%20-%20Status%20@%20Thu%20Jan%2003%20172037%202019_pliki/green.gif" width=16 height=16></A></TD> <TD align=center><A href="http://bb.intranet/cgi-bin/svcstatus.sh?HOST=EvohostnameL&SERVICE=disk"><IMG title=disk:green:23d18h19m border=0 alt=disk:green:23d18h19m src="red%20%20Xymon%20-%20Status%20@%20Thu%20Jan%2003%20172037%202019_pliki/green.gif" width=16 height=16></A></TD> <TD align=center>-</TD> <TD align=center><A href="http://bb.intranet/cgi-bin/svcstatus.sh?HOST=EvohostnameL&SERVICE=info"><IMG title=info:green:56.346.18.22 border=0 alt=info:green:56.346.18.22 src="red%20%20Xymon%20-%20Status%20@%20Thu%20Jan%2003%20172037%202019_pliki/green.gif" width=16 height=16></A></TD> <TD align=center>-</TD> <TD align=center><A href="http://bb.intranet/cgi-bin/svcstatus.sh?HOST=EvohostnameL&SERVICE=memory"><IMG title=memory:green:417d10h31m border=0 alt=memory:green:417d10h31m src="red%20%20Xymon%20-%20Status%20@%20Thu%20Jan%2003%20172037%202019_pliki/green.gif" width=16 height=16></A></TD> <TD align=center>-</TD> <TD align=center><A href="http://bb.intranet/cgi-bin/svcstatus.sh?HOST=EvohostnameL&SERVICE=nfs"><IMG title=nfs:green:417d11h10m border=0 alt=nfs:green:417d11h10m src="red%20%20Xymon%20-%20Status%20@%20Thu%20Jan%2003%20172037%202019_pliki/green.gif" width=16 height=16></A></TD> <TD align=center>-</TD> <TD align=center>-</TD> <TD align=center><A href="http://bb.intranet/cgi-bin/svcstatus.sh?HOST=EvohostnameL&SERVICE=procs"><IMG title=procs:green:101d05h45m border=0 alt=procs:green:101d05h45m src="red%20%20Xymon%20-%20Status%20@%20Thu%20Jan%2003%20172037%202019_pliki/green.gif" width=16 height=16></A></TD> <TD align=center>-</TD> <TD align=center><A href="http://bb.intranet/cgi-bin/svcstatus.sh?HOST=EvohostnameL&SERVICE=trends"><IMG title=trends:green:56.346.18.22 border=0 alt=trends:green:56.346.18.22 src="red%20%20Xymon%20-%20Status%20@%20Thu%20Jan%2003%20172037%202019_pliki/green.gif" width=16 height=16></A></TD> <TD align=center><A href="http://bb.intranet/cgi-bin/svcstatus.sh?HOST=EvohostnameL&SERVICE=unibackup"><IMG title=unibackup:red:24d05h19m border=0 alt=unibackup:red:24d05h19m src="red%20%20Xymon%20-%20Status%20@%20Thu%20Jan%2003%20172037%202019_pliki/red.gif" width=16 height=16></A></TD></TR> </tbody> </table> </html>
Что я уже пробовал:
<pre>namespace EvenetViewerBB { public partial class Form1 : Form { DataTable table; public Form1() { InitializeComponent(); InitTable(); } public class nameandalert { public string Host { get; set; } public string Alert { get; set; } } private void InitTable() { table = new DataTable("BigBrotherEventViewer"); table.Columns.Add("Host", typeof(String)); table.Columns.Add("Alert", typeof(String)); table.Columns.Add("Time", typeof(String)); EventviewBB.DataSource = table; } private void Form1_Load(object sender, EventArgs e) { //InitTable(); WebClient webClient = new WebClient(); string page = webClient.DownloadString(@"C:\temp\test3.htm"); HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument(); doc.LoadHtml(page); richTextBox1.Text = page; var namenodes = doc.DocumentNode.SelectNodes("//table[@border='0']/tbody/tr[2]/td[1]/a[2]"); var host = namenodes.Select(node => node.InnerText); var alertnodes = doc.DocumentNode.SelectNodes("//table[@cellpadding=2]/tbody/tr[2]/td[10]/a/"); var alert = alertnodes.Select(node => node.InnerText); table.Rows.Add(host); } } }
Bryian Tan
что не работает?