如何获取HTML元素并放入datagridview [英] How to grab HTML element and put in datagridview

查看:114
本文介绍了如何获取HTML元素并放入datagridview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的,



你能帮帮我。



我的HTML表有问题只抓住红色和黄色警报并放入DataGridView。我首先尝试在Htmlaiglity Pack的帮助下抓取一个特定项目,但它也不起作用。下面我发送HTML代码和C#代码



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

<!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>





我尝试过:





What I have tried:

<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);
          

        }
}
}

推荐答案

好的。不确定 html 标记是否搞砸了你把它粘贴在这里还是搞砸了你的开发机器。以下是基于此处发布的内容的一些建议



1.修复所有html错误,例如,确保< table> 有结束标记< / table> ,删除多余的< br /> 标记等等......

2.试图用 cellspacing 属性选择 table 的代码但是标记中没有。标记有 cellPadding

3.看起来这条线会抛出错误 // table [@ cellspacing ='2 因为缺少结束单引号。我会用 // table [@ cellpadding = 2 替换它以匹配html标记
Ok. not sure if the html markup was mess up went you paste it here or it was mess up on your development machine. Here are a few suggestion based on what posted here

1. fix all the html error, example, make sure the <table> has closing tag </table>, remove excessive <br/> tag , etc...
2. the code trying to select table with cellspacing property but there is none in the markup. the markup have cellPadding
3. look like this line gonna throw error //table[@cellspacing='2 because missing closing single quote. I would replace it with //table[@cellpadding=2 to match the html markup


这篇关于如何获取HTML元素并放入datagridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆