How to grab HTML element and put in DataGridView

  • Thread starter Thread starter 5ty
  • Start date Start date
5

5ty

Guest
Dears,

Could you help me.

I have a problem with the HTML table grab only the red and yellow alerts and put in the DataGridView. I tried first to grab a specific item with the help of Htmlaiglity Pack but it also does not work. Below I send HTML code and C# code

I want to look like in DataGrid view like this:

1410093.jpg

private void Form1_Load(object sender, EventArgs e)
{
InitTable();
HtmlAgilityPack.HtmlWeb web = new HtmlWeb();

var path = @"C:\temp\test1.htm";

var doc = new HtmlAgilityPack.HtmlDocument();
doc.Load(path);



var namenodes = doc.DocumentNode.SelectNodes("//table[@cellspacing='2]/tbody/tr[2]/td[1]/a[1]");
var host = namenodes.Select(node => node.InnerText);
var alertnodes = doc.DocumentNode.SelectNodes("//table[@cellspacing='2]/tbody/tr[2]/td[10]/a/");
var alert = alertnodes.Select(node => node.InnerText);
table.Rows.Add(host, alert);
}

HTML CODE


<!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>&nbsp;</TD></TR><!-- For the menu bar -->
<TR>
<TD vAlign=middle width="30%" align=left><FONT color=silver size=+1
face="Arial, Helvetica"><B>Xymon</B></FONT> </TD>
<TD vAlign=middle width="40%" align=center>
<CENTER><FONT color=silver size=+1 face="Arial, Helvetica"><B>Current
<FONT color=yellow>ALERT</FONT> Systems </B></FONT></CENTER></TD>
<TD vAlign=middle width="30%" align=right><FONT color=silver size=+1
face="Arial, Helvetica"><B>Thu Jan 3 17:21:26 CET 2019 </B></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 &gt; 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>&nbsp;</CENTER></TD>
<TD vAlign=bottom width=45 align=center><A
href="http://bb.intranet/cgi-bin/columndoc.sh?FicExist"><FONT
color=#87a9e5 size=-1><B>FicExist</B></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><B>JobsLogs-Httpd</B></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><B>JobsLogs-Jboss</B></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><B>JobsLogs-Tomcat</B></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><B>bbinfos</B></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><B>certExp</B></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><B>conn</B></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><B>cpu</B></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><B>disk</B></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><B>holdmgr</B></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><B>info</B></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><B>load</B></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><B>memory</B></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><B>msgs</B></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><B>nfs</B></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><B>noimg</B></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><B>noroot</B></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><B>procs</B></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><B>svcs</B></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><B>trends</B></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><B>unibackup</B></FONT></A> </TD></TR>
<TR class=line>
<TD noWrap align=left><A name=BFhostname>&nbsp;</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&amp;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&amp;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&amp;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&amp;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&amp;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&amp;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&amp;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&amp;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&amp;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>&nbsp;</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&amp;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&amp;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&amp;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&amp;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&amp;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&amp;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&amp;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&amp;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&amp;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>&nbsp;</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&amp;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&amp;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&amp;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&amp;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&amp;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&amp;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&amp;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&amp;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&amp;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&amp;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>

Continue reading...
 
Back
Top