本文介绍了HtmlAgilityPack - 从html表中获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我的程序使用HtmlAgilityPack并抓取一个HTML网页,将它存储在一个变量中,我试图从HTML分类标记(boardcontainer)下的两个表中获取。使用我当前的代码,它将搜索整个网页中的每个表并显示它们,但是当单元格为空时,它将引发异常: NullReferenceException未处理 - 对象引用。 HTML代码片段(在这种情况下,我在网站上搜索'Microsoft': < div class =boardcontainer> < table cellpadding =4cellspacing =1border = 0width =100%> < tr>< td colspan =6class =catbgheight =18>主数据库< / td>< / tr> < tr> < td class =windowbgwidth =28%align =center>公司名称< / td> < td class =windowbg宽度=12%align =center> 0870/0871< / td> < td class =windowbgwidth =12%align =center> 0844 / td> < td class = 12 %align =center>免费电话< / td> < td class =windowbgwidth =24%align =center>其他资讯< / td> < / tr> < tr> < td class = windowbg2 width = 28%align = center BGCOLOR =#FFFFCC>< a href = http://www.websitename.com/exit.php?site = www.microsoft.co.uk target =_ blank> Microsoft< / a>< / td>< td class = windowbg2 width = 12%align = center BGCOLOR =#FFFFCC> 700870 601 0100< / a>< / td>< td class = windowbg2 width = 12%align = center BGCOLOR =#FFFFCC> 0844800 2400< / a>< / td>< td class = windowbg2 width = 12%align = center BGCOLOR =#FFFFCC> 1901954 713950< ; / a>< / td>< td class = windowbg2 width = 12%align = center BGCOLOR =#FFFFCC>< / a>< / td>< td class = windowbg2 width = 24%中心BGCOLOR =#FFFFCC>< b>>< b>客户支持< / b>< br>< i>直接代理(无菜单)< / i>< br>< font size = 1> 0870 6010200< / font>< / td>< / tr> < tr> < td class = windowbg2 width = 28%align = center BGCOLOR =#FFFFCC>< a href = http://www.websitename.com/exit.php?site = www.microsoft.co.uk target =_ blank> Microsoft< / a>< / td>< td class = windowbg2 width = 12%align = center BGCOLOR =#FFFFCC> 700870 601 0100< / a>< / td>< td class = windowbg2 width = 12%align = center BGCOLOR =#FFFFCC> 0844800 2400< / a>< / td>< td class = windowbg2 width = 12%align = center BGCOLOR =#FFFFCC> 0118909 < / d>< / td>< td class = windowbg2 width = 24%align =中心BGCOLOR =#FFFFCC> < b>主英国总机< / b>< br>< i>要求接通所需部门< / i>< br>< font size = 1>也适用于0870 6010200< / font>< / td>< / tr> < tr> 这是我当前的代码,它只抓取表并显示行+单元,然后在Null时抛出异常。 string html = myRequest.GetResponse(); HtmlDocument htmlDoc = new HtmlDocument(); htmlDoc.LoadHtml(html); foreach(htmlDoc.DocumentNode.SelectNodes(// table)中的HtmlNode表) { Console.WriteLine(Found:+ table。 ID); foreach(HtmlNode row in table.SelectNodes(tr)) { Console.WriteLine(row); foreach(HtmlNode cell in row.SelectNodes(th | td))//在这里抛出异常 { Console.WriteLine(cell:+ cell.InnerText); } } } 如何将其更改为搜索特定的div类并从内部提取表? 感谢您阅读。 完整的HTML: <!DOCTYPE HTML PUBLIC - // W3C // DTD HTML 4.01 Transitional // ENhttp:// www.w3.org/TR/html4/loose.dtd\"> < META NAME =ROBOTSCONTENT =NOINDEX,NOFOLLOW> < meta http-equiv =Content-Typecontent =text / html; charset = ISO-8859-1/> < form method =postaction =sdfsd.php> < html> < head>< title> SAYNOTO0870.COM - 非地理替代电话号码< / title> < meta name ='copyright'content ='SAYNOTO0870.COM - 1999-2010'> < META name =y_keycontent =5a00e35b9f1986b0> < / head> < body> < BODY bgColor =#ffffe6> < table border =0width =100%id =headertable1> < tr> < td width =335valign =top> < font face ='Tahoma'size ='2'> < center>< b> < font size =6> SAY< font color =#FF0000> NO< / font> TO< font color =#FF0000> 0870< / font>字体> < / b>< / center> < / font> < font face ='Tahoma'size ='4'> < center>< b>< font size =2>非地理替代电话号码< / font>< / b>< font size =3>< font>< font face ='Tahoma'size ='2'>< / font>< br> < span style =font-weight:700>< font size =1>获得当天网站 BBC Radio 2和特色< br> ; 收听BBC Radio 2的 Jeremy Vine节目和卫报。< / font>< / span>< / center> < / td> < td width =403rowspan =2align =center> < a href =http://energy.saynoto0870.comtarget =_ blank>< img src =/ banners / energyheader.gifalt =节省金钱您的气体和电力width =420height =60border =0align =middle>< / a> < / td> < / TR>< /表> < tr> < td align =center> < tr> < td width =100%align =center> < tr> < td valign =middlebgcolor =#CCFFCCalign =centerwidth =180> < font face ='Tahoma'size ='2'> < b> < a href =/> < img src =/ images / home.gifalt =Homeborder =0>主页< / a>< / td> < td valign =middlebgcolor =#CCFFCCalign =centerwidth =143> < b> < font face ='Tahoma'size ='2'> < a href =/ cgi-bin / forum / YaBB.cgi> < img src =/ images / forum.gifalt =论坛论坛border =0>论坛< / a>< / td> < td valign =middlebgcolor =#CCFFCCalign =centerwidth =134> < font face =Tahomasize =2> < b> < a href =/ links.php> < img src =/ images / links.gifalt =链接border =0>链接< / a>< / td> < td valign =middlebgcolor =#CCFFCCalign =centerwidth =103> < font face =Tahomasize =2> < b> < a href =/ help.php> < img src =/ images / help.gifalt =帮助border =0>帮助< / a>< / td> < td valign =middlebgcolor =#CCFFCCalign =centerwidth =114> < font face =Tahomasize =2> < b> < a href =/ contact> < img src =/ images / contact.gifalt =联系我们border =0>联系我们< / a> < / td> < / tr> < tr> < td valign =middlebgcolor =#CCFFCCalign =centerwidth =321colspan =2> < font face ='Tahoma'size ='2'> < a href =/ search.php> < font face =Tahoma> < b> < font size =2> < img src =/ images / search.gifalt =搜索border =0>< / font>< / b>< / font>< font size = 2>< b>搜寻以寻找替代编号< / b>< / font>< / a>< / td> < td valign =middlebgcolor =#CCFFCCalign =centerwidth =365colspan =3> < font face ='Tahoma'size ='2'> < a href =/ add.php> < font face =Tahoma> < b> < font size =2> < / font>< / b>< / font>< / font> ;< font size =2>< b>在这里点击以添加新的备选号码< / b>< / font>< / a>< / td> < / tr> < / table> < / td> < / tr> < / table> < / td> < / tr> < / table> < br> < center> < script type =text / javascript><! - google_ad_client =pub-9959843696187618; google_ad_width = 468; google_ad_height = 60; google_ad_format =468x60_as; google_ad_type =text_image; // 2007-06-07:SAYNOTO0870-Header google_ad_channel =6422558175; google_color_border =ffffe6; google_color_bg =ffffe6; google_color_link =32527A; google_color_text =000000; google_color_url =2D8930; // - > < / script> < script type =text / javascript src =http://pagead2.googlesyndication.com/pagead/show_ads.js> < / script> < / center> < BR>< input type = hidden name =search_namevalue =Microsoft> < / form> < link rel =stylesheethref =search.csstype =text / css/> < table width =100%align =centerborder =0> < tr> < td>< font size =2> < div class =seperator>< / div> < div class =boardcontainer> < table cellpadding =4cellspacing =1border =0width =100%> < tr>< td colspan =6class =catbgheight =18>主数据库< / td>< / tr> < tr> < td class =windowbgwidth =28%align =center>公司名称< / td> < td class =windowbgwidth =12%align =center> 0870/0871< / td> < td class =windowbgwidth =12%align =center> 0844/0845< / td> < td class =windowbgwidth =12%align =center> 01/02/03< / td> < td class =windowbgwidth =12%align =center>免费电话< / td> < td class =windowbgwidth =24%align =center>其他资讯< / td> < / tr> < tr> < td class = windowbg2 width = 28%align = center BGCOLOR =#FFFFCC>< a href = http://www.saynoto0870.com/exit.php?site = www.microsoft .co.uk target =_ blank> Microsoft< / a>< / td>< td class = windowbg2 width = 12%align = center BGCOLOR =#FFFFCC> 0870 601 0100< / a>< / td>< td class = windowbg2 width = 12%align = center BGCOLOR =#FFFFCC> 0844 800 2400< / a>< / td>< td class = windowbg2 width = 12%align = center BGCOLOR =#FFFFCC> 01954 713950< / a>< / td>< td class = windowbg2 width = 12%align = center BGCOLOR =#FFFFCC> < / a>< / td>< td class = windowbg2 width = 24%align = center BGCOLOR =#FFFFCC> < b>客户支持< / b>< br>< i>直接代理(无菜单)< / i>< br>< font size = 1>同样适用于0870 6010200< / font>< ; / TD>< / TR> < tr> < td class = windowbg2 width = 28%align = center BGCOLOR =#FFFFCC>< a href = http://www.saynoto0870.com/exit.php?site = www.microsoft.co.uk target =_ blank> Microsoft< / a>< / td>< td class = windowbg2 width = 12%align = center BGCOLOR =#FFFFCC> 0870 601 0100< / a>< / td>< td class = windowbg2 width = 12%align = center BGCOLOR =#FFFFCC> 0844 800 2400< / a>< / td>< td class = windowbg2 width = 12%align = center BGCOLOR =#FFFFCC> 0118 909 7800< / a>< / td>< td class = windowbg2 width = 12%align = center BGCOLOR =#FFFFCC> < / a>< / td>< td class = windowbg2 width = 24%align = center BGCOLOR =#FFFFCC> < b>主要英国总机< / b>< br>< i>要求接通所需部门< / i>< br>< font size = 1>同样适用于0870 6010200< / font> < / TD>< / TR> < tr> < td class = windowbg2 width = 28%align = center BGCOLOR =#FFFFCC>< a href = http://www.saynoto0870.com/exit.php?site = www.microsoft.co.uk target =_ blank> Microsoft< / a>< / td>< td class = windowbg2 width = 12%align = center BGCOLOR =#FFFFCC> 0870 601 0100< / a>< / td>< td class = windowbg2 width = 12%align = center BGCOLOR =#FFFFCC> 0844 800 2400< / a>< / td>< td class = windowbg2 width = 12%align = center BGCOLOR =#FFFFCC> + 35314502113< / a>< / td>< td class = windowbg2 width = 12%align = center BGCOLOR =#FFFFCC> < / a>< / td>< td class = windowbg2 width = 24%align = center BGCOLOR =#FFFFCC> < b>客户支持< / b>< br>< i>作为微软爱尔兰的解决方案与英国08号数字相同< / i>< br>使用1899(或类似)降低成本< br>< ; font size = 1>同样适用于0870 6010200< / font>< / td>< / tr> < tr> < td class = windowbg2 width = 28%align = center BGCOLOR =#FFFFCC>< a href = http://www.saynoto0870.com/exit.php?site = www.microsoft.co.uk target =_ blank> Microsoft< / a>< / td>< td class = windowbg2 width = 12%align = center BGCOLOR =#FFFFCC> 0870 241 1963< / a>< / td>< td class = windowbg2 width = 12%align = center BGCOLOR =#FFFFCC> 0844 800 2400< / a>< / td>< td class = windowbg2 width = 12%align = center BGCOLOR =#FFFFCC> 020 3147 4930< / a>< / td>< td class = windowbg2 width = 12%align = center BGCOLOR =#FFFFCC> 0800 0188354< / a>< / td>< td class = windowbg2 width = 24%align = center BGCOLOR =#FFFFCC> < b>产品激活< / b>< br>< i>首页&商业(批量授权)< / i>< br>< font size = 1>另外:0800 018 8364& +800 2284 8283< br>也用于0870 6010100& 0870 6010200< / font>< / td>< / tr> < tr> < td class = windowbg2 width = 28%align = center BGCOLOR =#FFFFCC>< a href = http://www.saynoto0870.com/exit.php?site = www.microsoft.co.uk target =_ blank> Microsoft< / a>< / td>< td class = windowbg2 width = 12%align = center BGCOLOR =#FFFFCC> 0870 241 1963< / a>< / td>< td class = windowbg2 width = 12%align = center BGCOLOR =#FFFFCC> < / t>< / td>< td class = windowbg2 width = 12%align = center BGCOLOR =#FFFFCC> < / t>< / td>< td class = windowbg2 width = 12%align = center BGCOLOR =#FFFFCC> 0800 9179016< / a>< / td>< td class = windowbg2 width = 24%align = center BGCOLOR =#FFFFCC> < b>批量授权< / b>< / td>< / tr> < tr> < td class = windowbg2 width = 28%align = center BGCOLOR =#FFFFCC>< a href = http://www.saynoto0870.com/exit.php?site = www.microsoft.co.uk target =_ blank> Microsoft< / a>< / td>< td class = windowbg2 width = 12%align = center BGCOLOR =#FFFFCC> < / t>< / td>< td class = windowbg2 width = 12%align = center BGCOLOR =#FFFFCC> < / t>< / td>< td class = windowbg2 width = 12%align = center BGCOLOR =#FFFFCC> 020 3027 6039< / a>< / td>< td class = windowbg2 width = 12%align = center BGCOLOR =#FFFFCC> 0800 7318457< / a>< / td>< td class = windowbg2 width = 24%align = center BGCOLOR =#FFFFCC> < b>在线服务支持< / b>< br>< i> MSN,Hotmail,Live,Messenger等< / i>< br>< font size = 1>另外:0800 587 2920< / font> ;< / TD>< / TR> < tr> < td class = windowbg2 width = 28%align = center BGCOLOR =#FFFFCC>< a href = http://www.saynoto0870.com/exit.php?site = www.microsoft.co.uk target =_ blank> Microsoft< / a>< / td>< td class = windowbg2 width = 12%align = center BGCOLOR =#FFFFCC> 0870 607 0700< / a>< / td>< td class = windowbg2 width = 12%align = center BGCOLOR =#FFFFCC> 0844 800 6006< / a>< / td>< td class = windowbg2 width = 12%align = center BGCOLOR =#FFFFCC> + 35317065353< / a>< / td>< td class = windowbg2 width = 12%align = center BGCOLOR =#FFFFCC> < / a>< / td>< td class = windowbg2 width = 24%align = center BGCOLOR =#FFFFCC> < b>向合作伙伴热线< / b>< br>< i>回答相同的选项< / i>< br>使用1899(或类似的)降低成本< / td>< / tr> < tr> < td class = windowbg2 width = 28%align = center BGCOLOR =#FFFFCC>< a href = http://www.saynoto0870.com/exit.php?site = www.microsoft.co.uk target =_ blank> Microsoft< / a>< / td>< td class = windowbg2 width = 12%align = center BGCOLOR =#FFFFCC> 0870 607 0700< / a>< / td>< td class = windowbg2 width = 12%align = center BGCOLOR =#FFFFCC> 0844 800 6006< / a>< / td>< td class = windowbg2 width = 12%align = center BGCOLOR =#FFFFCC> < / t>< / td>< td class = windowbg2 width = 12%align = center BGCOLOR =#FFFFCC> 0800 9173128< / a>< / td>< td class = windowbg2 width = 24%align = center BGCOLOR =#FFFFCC> < b>合作伙伴网络区域服务中心< / b>< br>< / gt;< / td>< / tr>成员问题和工具,优势和资源查询帮助< / i& < tr> < td class = windowbg2 width = 28%align = center BGCOLOR =#FFFFCC>< a href = http://www.saynoto0870.com/exit.php?site = www.microsoft.co.uk target =_ blank> Microsoft< / a>< / td>< td class = windowbg2 width = 12%align = center BGCOLOR =#FFFFCC> 0870 601 0100< / a>< / td>< td class = windowbg2 width = 12%align = center BGCOLOR =#FFFFCC> 0844 800 2400< / a>< / td>< td class = windowbg2 width = 12%align = center BGCOLOR =#FFFFCC> < / t>< / td>< td class = windowbg2 width = 12%align = center BGCOLOR =#FFFFCC> 0800 0324479< / a>< / td>< td class = windowbg2 width = 24%align = center BGCOLOR =#FFFFCC> < b> Direct Services< / b>< br>< font size = 1>同样适用于0870 6010200< / font>< / td>< / tr> < tr> < td class = windowbg2 width = 28%align = center BGCOLOR =#FFFFCC>< a href = http://www.saynoto0870.com/exit.php?site = www.microsoft.co.uk / msdn target =_ blank> Microsoft< / a>< / td>< td class = windowbg2 width = 12%align = center BGCOLOR =#FFFFCC> 0870 601 0100< / a>< / td>< td class = windowbg2 width = 12%align = center BGCOLOR =#FFFFCC> 0844 800 2400< / a>< / td>< td class = windowbg2 width = 12%align = center BGCOLOR =#FFFFCC> + 35318831002< / a>< / td>< td class = windowbg2 width = 12%align = center BGCOLOR =#FFFFCC> 0800 0517215< / a>< / td>< td class = windowbg2 width = 24%align = center BGCOLOR =#FFFFCC> < b> MSDN(Microsoft Developers Network)< / b>< br>在使用1899(或类似)调用+353降低成本时< br>< font size = 1>同样适用于0870 6010200< / font> < / TD>< / TR> < tr> < td class = windowbg2 width = 28%align = center BGCOLOR =#FFFFCC>< a href = http://www.saynoto0870.com/exit.php?site = www.microsoft.co.uk / technet target =_ blank> Microsoft< / a>< / td>< td class = windowbg2 width = 12%align = center BGCOLOR =#FFFFCC> 0870 601 0100< / a>< / td>< td class = windowbg2 width = 12%align = center BGCOLOR =#FFFFCC> 0844 800 2400< / a>< / td>< td class = windowbg2 width = 12%align = center BGCOLOR =#FFFFCC> + 35318831002< / a>< / td>< td class = windowbg2 width = 12%align = center BGCOLOR =#FFFFCC> 0800 281221< / a>< / td>< td class = windowbg2 width = 24%align = center BGCOLOR =#FFFFCC> < b> Microsoft Technet< / b>< br>当使用1899(或类似)调用+353降低成本< br>< font size = 1>同样适用于0870 6010200< / font>< / td> < / TR> < tr> < td class = windowbg2 width = 28%align = center BGCOLOR =#FFFFCC>< a href = http://www.saynoto0870.com/exit.php?site = www.xbox.co.uk target =_ blank> Microsoft XBOX< / a>< / td>< td class = windowbg2 width = 12%align = center BGCOLOR =#FFFFCC> < / t>< / td>< td class = windowbg2 width = 12%align = center BGCOLOR =#FFFFCC> < / t>< / td>< td class = windowbg2 width = 12%align = center BGCOLOR =#FFFFCC> 020 7365 9792< / a>< / td>< td class = windowbg2 width = 12%align = center BGCOLOR =#FFFFCC> 0800 5871102< / a>< / td>< td class = windowbg2 width = 24%align = center BGCOLOR =#FFFFCC> < b>客户支持< / b>< / td>< / tr> < tr> < / tr> < / table> < / div>< br /> < table width =100%align =centerborder =0> < tr>< td>< font size =2> < div class =seperator>< / div> < div class =boardcontainer> < table cellpadding =4cellspacing =1border =0width =100%> < tr>< td colspan =6class =catbgheight =18> Unverified Numbers Database< / td>< / tr> < tr> < td class =windowbgwidth =28%align =center>公司名称< / td> < td class =windowbgwidth =12%align =center> 0870/0871< / td> < td class =windowbgwidth =12%align =center> 0844/0845< / td> < td class =windowbgwidth =12%align =center> 01/02/03< / td> < td class =windowbgwidth =12%align =center>免费电话< / td> < td class =windowbgwidth =24%align =center>其他资讯< / td> < / tr> < td class = windowuv width = 28%align = center BGCOLOR =#CCFFFF> Microsoft< / td>< td class = windowuv width = 12%align = center BGCOLOR =#CCFFFF> 0870 501 0800< / a>< / td>< td class = windowuv width = 12%align = center BGCOLOR =#CCFFFF> 0844 800 8338< / a>< / td>< td class = windowuv width = 12%align = center BGCOLOR =#CCFFFF> 0118 909 7994< / a>< / td>< td class = windowuv width = 12%align = center BGCOLOR =#CCFFFF> < / td>< td class = windowuv width = 24%align = center BGCOLOR =#CCFFFF> < b> Premier支持< / b>< / td>< / tr> < tr> < td class = windowuv width = 28%align = center BGCOLOR =#CCFFFF> Microsoft AskPartner(许可)< / a>< / td>< td class = windowuv width = 12%align = center BGCOLOR =#CCFFFF> 0870 607 0700< / a>< / td>< td class = windowuv width = 12%align = center BGCOLOR =#CCFFFF> < / td>< / td>< td class = windowuv width = 12%align = center BGCOLOR =#CCFFFF> 020 8784 1000< / a>< / td>< td class = windowuv width = 12%align = center BGCOLOR =#CCFFFF> < / td>< td class = windowuv width = 24%align = center BGCOLOR =#CCFFFF> AskPartner团队所在的金斯敦Sitel UK总机。问问微软团队。 0800 - 1800.< / td>< / tr> < tr> < td class = windowuv width = 28%align = center BGCOLOR =#CCFFFF> Microsoft Office Live Meeting< / td>< td class = windowuv width = 12%align = center BGCOLOR =#CCFFFF> < / td>< / td>< td class = windowuv width = 12%align = center BGCOLOR =#CCFFFF> < / td>< / td>< td class = windowuv width = 12%align = center BGCOLOR =#CCFFFF> 020 3024 9260< / a>< / td>< td class = windowuv width = 12%align = center BGCOLOR =#CCFFFF> 0800 0854811< / a>< / td>< td class = windowuv width = 24%align = center BGCOLOR =#CCFFFF> EMC Meeting on Meeting Place< / td>< / tr> < / tr> < / table> < / div>< br /> < center> < a href =http://homephone.consumerchoices.co.uk/?partner=saynoto0870target =_ blank> < img src =/ banners / consumerchoices.pngborder =0alt =ConsumerChoicesalign =middle>< / img>< / a> < BR>< BR> < / center> < div class =seperator> < table cellpadding =4cellspacing =1border =0width =100%> < tr> < td class =titlebgalign =centercolspan =2> 信息中心< / td> < / tr> < td class =windowbg2> < div style =float:left; width:59%; text-align:left;> < span class =small>请使用联系我们选项,以报告您在网站上发现的任何不正确的数字。感谢您的支持。< / span>< br /> < / div> < div style =float:left; width:40%; text-align:left;> < div class =smallstyle =float:left; width:49%;>< span style =color:red;>< b> lllll< / b<< ; /跨度>主数据库 - 已检查并在检查时正确运行的号码。 < / div>< div class =smallstyle =float:left; width:49%;>< span style =color: #CCFFFF;>< b取代; LLLLL< / b>< /跨度>未经验证的号码 - 访问者添加到网站的号码,尚未经过验证是正确的。请使用页面顶部的联系我们链接,告诉我们这些工作是否适用于您(&或不起作用)。< / div> < / div> < / td> < / tr> < / table> < / div> < / font>< / td> < / tr> < / table> < br> < head> < style> < / style> < / head> < b> < center> < font color ='red'> < / center> < / b> < / font> < BR> < center> < script type =text / javascript><! - google_ad_client =pub-9959843696187618; google_ad_width = 728; google_ad_height = 90; google_ad_format =728x90_as; google_ad_type =text_image; // 2007-06-07:SAYNOTO0870-Footer google_ad_channel =7459969292; google_color_border =FFFFE6; google_color_bg =FFFFE6; google_color_link =32527A; google_color_text =000000; google_color_url =2D8930; // - > < / script> < script type =text / javascriptsrc =http://pagead2.googlesyndication.com/pagead/show_ads.js>< / script> < BR>< / center> < BR>< center>< B> < font face =Tahomasize =2> 网站和内容©1999-2011 SAYNOTO0870.COM。& nbsp;保留所有权利< / b> ;. < br>< b>需要书面许可才能复制此网站中的任何内容。 < / B>< /中心],[< /字体> < script src =http://www.google-analytics.com/urchin.jstype =text / javascript>< / script> < script type =text / javascript> _uacct =UA-194609-1; urchinTracker();< / script> < / body>< / html> 解决方案以下XPATH允许您搜索特定的 DIV (带班级'boardcontainer') // div [@ class ='boardcontainer'] / table 要处理空行,或不是返回的 HtmlNodeCollection 是 null 。 是一个完整的例子: HtmlDocument htmlDoc = new HtmlDocument(); htmlDoc.LoadHtml(html); $ b foreach(htmlDoc.DocumentNode.SelectNodes中的HtmlNode表(// div [@ class ='boardcontainer'] / table)) { Console.WriteLine(发现:+ table.Id); foreach(HtmlNode row in table.SelectNodes(tr)) { Console.WriteLine(row); HtmlNodeCollection cells = row.SelectNodes(th | td); if(cells == null) { continue; } foreach(单元格中的HtmlNode单元格) { Console.WriteLine(cell:+ cell.InnerText); $ / code $ / pre 你也应该检查一下表被发现,如果找到的表包含行。 My program uses HtmlAgilityPack and grabs a HTML web page, stores it in a variable and I'm trying to get from the HTML two tables which are under specific Div Class tags (boardcontainer). With my current code it searches through the whole web page for every table and displays them but when a cell is empty it throws an exception:"NullReferenceException was unhandled - Object reference not set to an instance of an object.".A snippet of the HTML (In this case I'm searching 'Microsoft' on the website:<div class="boardcontainer"><table cellpadding="4" cellspacing="1" border="0" width="100%"><tr><td colspan="6" class="catbg" height="18" >Main Database</td></tr><tr> <td class="windowbg" width="28%" align="center">Company Name</td> <td class="windowbg" width="12%" align="center">0870 / 0871</td> <td class="windowbg" width="12%" align="center">0844 / 0845</td> <td class="windowbg" width="12%" align="center">01 / 02 / 03</td> <td class="windowbg" width="12%" align="center">Freephone</td> <td class="windowbg" width="24%" align="center">Other Information</td></tr> <tr><td class=windowbg2 width=28% align=center BGCOLOR=#FFFFCC><a href=http://www.websitename.com/exit.php?site=www.microsoft.co.uk target="_blank">Microsoft</a></td><td class=windowbg2 width=12% align=center BGCOLOR=#FFFFCC>�0870 601 0100</a></td><td class=windowbg2 width=12% align=center BGCOLOR=#FFFFCC>�0844 800 2400</a></td><td class=windowbg2 width=12% align=center BGCOLOR=#FFFFCC>�01954 713950</a></td><td class=windowbg2 width=12% align=center BGCOLOR=#FFFFCC>�</a></td><td class=windowbg2 width=24% align=center BGCOLOR=#FFFFCC>�<b>Customer Support</b><br><i>Straight to agent (no menu)</i><br><font size=1>Also for 0870 6010200</font></td></tr> <tr><td class=windowbg2 width=28% align=center BGCOLOR=#FFFFCC><a href=http://www.websitename.com/exit.php?site=www.microsoft.co.uk target="_blank">Microsoft</a></td><td class=windowbg2 width=12% align=center BGCOLOR=#FFFFCC>�0870 601 0100</a></td><td class=windowbg2 width=12% align=center BGCOLOR=#FFFFCC>�0844 800 2400</a></td><td class=windowbg2 width=12% align=center BGCOLOR=#FFFFCC>�0118 909 7800</a></td><td class=windowbg2 width=12% align=center BGCOLOR=#FFFFCC>�</a></td><td class=windowbg2 width=24% align=center BGCOLOR=#FFFFCC>�<b>Main UK Switchboard</b><br><i>Ask to be put through to required department</i><br><font size=1>Also for 0870 6010200</font></td></tr> <tr>This is my current code which only grabs tables and displays the rows + cells then throws an exception upon Null. string html = myRequest.GetResponse(); HtmlDocument htmlDoc = new HtmlDocument(); htmlDoc.LoadHtml(html); foreach (HtmlNode table in htmlDoc.DocumentNode.SelectNodes("//table")) { Console.WriteLine("Found: " + table.Id); foreach (HtmlNode row in table.SelectNodes("tr")) { Console.WriteLine("row"); foreach (HtmlNode cell in row.SelectNodes("th|td")) //Exception is thrown here { Console.WriteLine("cell: " + cell.InnerText); } } }How can I change this to search the specific div class and extract the table from within?Thank you for reading.FULL HTML: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW"><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /><form method="post" action="sdfsd.php"><html><head><title>SAYNOTO0870.COM - Non-Geographical Alternative Telephone Numbers</title><meta name='copyright' content='SAYNOTO0870.COM - 1999-2010'><META name="y_key" content="5a00e35b9f1986b0" ></head><body><BODY bgColor=#ffffe6><table border="0" width="100%" id="headertable1"> <tr> <td width="335" valign="top"><font face='Tahoma' size='2'> <center><b> <font size="6">SAY<font color="#FF0000">NO</font>TO<font color="#FF0000">0870</font>.COM</font></b></center></font><font face='Tahoma' size='4'><center><b><font size="2">Non-Geographical Alternative Telephone Numbers</font></b><font size="3"></font><font face='Tahoma' size='2'></font><br><span style="font-weight: 700"><font size="1">Awarded Website Of The Day byBBC Radio 2, and featured<br>on the BBC Radio 2'sJeremy Vine show and The Guardian.</font></span></center> </td> <td width="403" rowspan="2" align="center"><a href="http://energy.saynoto0870.com" target="_blank"><img src="/banners/energyheader.gif" alt="Save Money on your Gas and Electricity" width="420" height="60" border="0" align="middle"></a> </td> </tr></table><table width="92%" cellspacing="1" cellpadding="0" border="0" align="CENTER"> <tr> <td align="center"> <table bgcolor="#AFC6DB" width="100%" cellspacing="0" cellpadding="0" align="center"> <tr> <td width="100%" align="center"> <table border="0" width="100%" cellpadding="3" cellspacing="0" bgcolor="#AFC6DB" align="center"> <tr> <td valign="middle" bgcolor="#CCFFCC" align="center" width="180"><font face='Tahoma' size='2'> <b><a href="/"> <img src="/images/home.gif" alt="Home" border="0">Home</a></td> <td valign="middle" bgcolor="#CCFFCC" align="center" width="143"> <b><font face='Tahoma' size='2'> <a href="/cgi-bin/forum/YaBB.cgi"> <img src="/images/forum.gif" alt="Discussion Forum" border="0">Discussion Forum</a></td> <td valign="middle" bgcolor="#CCFFCC" align="center" width="134"> <font face="Tahoma" size="2"> <b> <a href="/links.php"> <img src="/images/links.gif" alt="Links" border="0">Links</a></td> <td valign="middle" bgcolor="#CCFFCC" align="center" width="103"> <font face="Tahoma" size="2"> <b> <a href="/help.php"> <img src="/images/help.gif" alt="Help" border="0">Help</a></td> <td valign="middle" bgcolor="#CCFFCC" align="center" width="114"> <font face="Tahoma" size="2"> <b> <a href="/contact"> <img src="/images/contact.gif" alt="Contact Us" border="0">Contact Us</a> </td> </tr> <tr> <td valign="middle" bgcolor="#CCFFCC" align="center" width="321" colspan="2"><font face='Tahoma' size='2'> <a href="/search.php"> <font face="Tahoma"> <b> <font size="2"> <img src="/images/search.gif" alt="Search" border="0"></font></b></font><font size="2"><b>Search to find an alternative number</b></font></a></td> <td valign="middle" bgcolor="#CCFFCC" align="center" width="365" colspan="3"><font face='Tahoma' size='2'> <a href="/add.php"> <font face="Tahoma"> <b> <font size="2"> <img src="/images/addno.gif" alt="Add A New Number" border="0"></font></b></font><font size="2"><b>Click here to add a new alternative number</b></font></a></td> </tr> </table> </td> </tr> </table> </td> </tr></table><br><center><script type="text/javascript"><!--google_ad_client = "pub-9959843696187618";google_ad_width = 468;google_ad_height = 60;google_ad_format = "468x60_as";google_ad_type = "text_image";//2007-06-07: SAYNOTO0870-Headergoogle_ad_channel = "6422558175";google_color_border = "ffffe6";google_color_bg = "ffffe6";google_color_link = "32527A";google_color_text = "000000";google_color_url = "2D8930";//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script></center><BR><input type=hidden name="search_name" value="Microsoft"></form><link rel="stylesheet" href="search.css" type="text/css" /> <table width="100%" align="center" border="0"> <tr> <td><font size="2"><div class="seperator"></div><div class="boardcontainer"><table cellpadding="4" cellspacing="1" border="0" width="100%"><tr><td colspan="6" class="catbg" height="18" >Main Database</td></tr><tr> <td class="windowbg" width="28%" align="center">Company Name</td> <td class="windowbg" width="12%" align="center">0870 / 0871</td> <td class="windowbg" width="12%" align="center">0844 / 0845</td> <td class="windowbg" width="12%" align="center">01 / 02 / 03</td> <td class="windowbg" width="12%" align="center">Freephone</td> <td class="windowbg" width="24%" align="center">Other Information</td></tr> <tr><td class=windowbg2 width=28% align=center BGCOLOR=#FFFFCC><a href=http://www.saynoto0870.com/exit.php?site=www.microsoft.co.uk target="_blank">Microsoft</a></td><td class=windowbg2 width=12% align=center BGCOLOR=#FFFFCC> 0870 601 0100</a></td><td class=windowbg2 width=12% align=center BGCOLOR=#FFFFCC> 0844 800 2400</a></td><td class=windowbg2 width=12% align=center BGCOLOR=#FFFFCC> 01954 713950</a></td><td class=windowbg2 width=12% align=center BGCOLOR=#FFFFCC> </a></td><td class=windowbg2 width=24% align=center BGCOLOR=#FFFFCC> <b>Customer Support</b><br><i>Straight to agent (no menu)</i><br><font size=1>Also for 0870 6010200</font></td></tr> <tr><td class=windowbg2 width=28% align=center BGCOLOR=#FFFFCC><a href=http://www.saynoto0870.com/exit.php?site=www.microsoft.co.uk target="_blank">Microsoft</a></td><td class=windowbg2 width=12% align=center BGCOLOR=#FFFFCC> 0870 601 0100</a></td><td class=windowbg2 width=12% align=center BGCOLOR=#FFFFCC> 0844 800 2400</a></td><td class=windowbg2 width=12% align=center BGCOLOR=#FFFFCC> 0118 909 7800</a></td><td class=windowbg2 width=12% align=center BGCOLOR=#FFFFCC> </a></td><td class=windowbg2 width=24% align=center BGCOLOR=#FFFFCC> <b>Main UK Switchboard</b><br><i>Ask to be put through to required department</i><br><font size=1>Also for 0870 6010200</font></td></tr> <tr><td class=windowbg2 width=28% align=center BGCOLOR=#FFFFCC><a href=http://www.saynoto0870.com/exit.php?site=www.microsoft.co.uk target="_blank">Microsoft</a></td><td class=windowbg2 width=12% align=center BGCOLOR=#FFFFCC> 0870 601 0100</a></td><td class=windowbg2 width=12% align=center BGCOLOR=#FFFFCC> 0844 800 2400</a></td><td class=windowbg2 width=12% align=center BGCOLOR=#FFFFCC> +35314502113</a></td><td class=windowbg2 width=12% align=center BGCOLOR=#FFFFCC> </a></td><td class=windowbg2 width=24% align=center BGCOLOR=#FFFFCC> <b>Customer Support</b><br><i>Answers as Microsoft Ireland with same options as UK 08 numbers</i><br>Reduce cost using 1899 (or similar)<br><font size=1>Also for 0870 6010200</font></td></tr> <tr><td class=windowbg2 width=28% align=center BGCOLOR=#FFFFCC><a href=http://www.saynoto0870.com/exit.php?site=www.microsoft.co.uk target="_blank">Microsoft</a></td><td class=windowbg2 width=12% align=center BGCOLOR=#FFFFCC> 0870 241 1963</a></td><td class=windowbg2 width=12% align=center BGCOLOR=#FFFFCC> 0844 800 2400</a></td><td class=windowbg2 width=12% align=center BGCOLOR=#FFFFCC> 020 3147 4930</a></td><td class=windowbg2 width=12% align=center BGCOLOR=#FFFFCC> 0800 0188354</a></td><td class=windowbg2 width=24% align=center BGCOLOR=#FFFFCC> <b>Product Activation</b><br><i>Home & Business (Volume Licensing)</i><br><font size=1>Also: 0800 018 8364 & +800 2284 8283<br>Also for 0870 6010100 & 0870 6010200</font></td></tr> <tr><td class=windowbg2 width=28% align=center BGCOLOR=#FFFFCC><a href=http://www.saynoto0870.com/exit.php?site=www.microsoft.co.uk target="_blank">Microsoft</a></td><td class=windowbg2 width=12% align=center BGCOLOR=#FFFFCC> 0870 241 1963</a></td><td class=windowbg2 width=12% align=center BGCOLOR=#FFFFCC> </a></td><td class=windowbg2 width=12% align=center BGCOLOR=#FFFFCC> </a></td><td class=windowbg2 width=12% align=center BGCOLOR=#FFFFCC> 0800 9179016</a></td><td class=windowbg2 width=24% align=center BGCOLOR=#FFFFCC> <b>Volume Licensing</b></td></tr> <tr><td class=windowbg2 width=28% align=center BGCOLOR=#FFFFCC><a href=http://www.saynoto0870.com/exit.php?site=www.microsoft.co.uk target="_blank">Microsoft</a></td><td class=windowbg2 width=12% align=center BGCOLOR=#FFFFCC> </a></td><td class=windowbg2 width=12% align=center BGCOLOR=#FFFFCC> </a></td><td class=windowbg2 width=12% align=center BGCOLOR=#FFFFCC> 020 3027 6039</a></td><td class=windowbg2 width=12% align=center BGCOLOR=#FFFFCC> 0800 7318457</a></td><td class=windowbg2 width=24% align=center BGCOLOR=#FFFFCC> <b>Online Services Support</b><br><i>MSN, Hotmail, Live, Messenger etc</i><br><font size=1>Also: 0800 587 2920</font></td></tr> <tr><td class=windowbg2 width=28% align=center BGCOLOR=#FFFFCC><a href=http://www.saynoto0870.com/exit.php?site=www.microsoft.co.uk target="_blank">Microsoft</a></td><td class=windowbg2 width=12% align=center BGCOLOR=#FFFFCC> 0870 607 0700</a></td><td class=windowbg2 width=12% align=center BGCOLOR=#FFFFCC> 0844 800 6006</a></td><td class=windowbg2 width=12% align=center BGCOLOR=#FFFFCC> +35317065353</a></td><td class=windowbg2 width=12% align=center BGCOLOR=#FFFFCC> </a></td><td class=windowbg2 width=24% align=center BGCOLOR=#FFFFCC> <b>Ask Partner Hotline</b><br><i>Answers with same options</i><br>Reduce cost using 1899 (or similar)</td></tr> <tr><td class=windowbg2 width=28% align=center BGCOLOR=#FFFFCC><a href=http://www.saynoto0870.com/exit.php?site=www.microsoft.co.uk target="_blank">Microsoft</a></td><td class=windowbg2 width=12% align=center BGCOLOR=#FFFFCC> 0870 607 0700</a></td><td class=windowbg2 width=12% align=center BGCOLOR=#FFFFCC> 0844 800 6006</a></td><td class=windowbg2 width=12% align=center BGCOLOR=#FFFFCC> </a></td><td class=windowbg2 width=12% align=center BGCOLOR=#FFFFCC> 0800 9173128</a></td><td class=windowbg2 width=24% align=center BGCOLOR=#FFFFCC> <b>Partner Network Regional Service Centre</b><br><i>Help with membership questions and tools, benefits and resource queries</i></td></tr> <tr><td class=windowbg2 width=28% align=center BGCOLOR=#FFFFCC><a href=http://www.saynoto0870.com/exit.php?site=www.microsoft.co.uk target="_blank">Microsoft</a></td><td class=windowbg2 width=12% align=center BGCOLOR=#FFFFCC> 0870 601 0100</a></td><td class=windowbg2 width=12% align=center BGCOLOR=#FFFFCC> 0844 800 2400</a></td><td class=windowbg2 width=12% align=center BGCOLOR=#FFFFCC> </a></td><td class=windowbg2 width=12% align=center BGCOLOR=#FFFFCC> 0800 0324479</a></td><td class=windowbg2 width=24% align=center BGCOLOR=#FFFFCC> <b>Direct Services</b><br><font size=1>Also for 0870 6010200</font></td></tr> <tr><td class=windowbg2 width=28% align=center BGCOLOR=#FFFFCC><a href=http://www.saynoto0870.com/exit.php?site=www.microsoft.co.uk/msdn target="_blank">Microsoft</a></td><td class=windowbg2 width=12% align=center BGCOLOR=#FFFFCC> 0870 601 0100</a></td><td class=windowbg2 width=12% align=center BGCOLOR=#FFFFCC> 0844 800 2400</a></td><td class=windowbg2 width=12% align=center BGCOLOR=#FFFFCC> +35318831002</a></td><td class=windowbg2 width=12% align=center BGCOLOR=#FFFFCC> 0800 0517215</a></td><td class=windowbg2 width=24% align=center BGCOLOR=#FFFFCC> <b>MSDN (Microsoft Developers Network)</b><br>When calling +353 reduce cost using 1899 (or similar)<br><font size=1>Also for 0870 6010200</font></td></tr> <tr><td class=windowbg2 width=28% align=center BGCOLOR=#FFFFCC><a href=http://www.saynoto0870.com/exit.php?site=www.microsoft.co.uk/technet target="_blank">Microsoft</a></td><td class=windowbg2 width=12% align=center BGCOLOR=#FFFFCC> 0870 601 0100</a></td><td class=windowbg2 width=12% align=center BGCOLOR=#FFFFCC> 0844 800 2400</a></td><td class=windowbg2 width=12% align=center BGCOLOR=#FFFFCC> +35318831002</a></td><td class=windowbg2 width=12% align=center BGCOLOR=#FFFFCC> 0800 281221</a></td><td class=windowbg2 width=24% align=center BGCOLOR=#FFFFCC> <b>Microsoft Technet</b><br>When calling +353 reduce cost using 1899 (or similar)<br><font size=1>Also for 0870 6010200</font></td></tr> <tr><td class=windowbg2 width=28% align=center BGCOLOR=#FFFFCC><a href=http://www.saynoto0870.com/exit.php?site=www.xbox.co.uk target="_blank">Microsoft XBOX</a></td><td class=windowbg2 width=12% align=center BGCOLOR=#FFFFCC> </a></td><td class=windowbg2 width=12% align=center BGCOLOR=#FFFFCC> </a></td><td class=windowbg2 width=12% align=center BGCOLOR=#FFFFCC> 020 7365 9792</a></td><td class=windowbg2 width=12% align=center BGCOLOR=#FFFFCC> 0800 5871102</a></td><td class=windowbg2 width=24% align=center BGCOLOR=#FFFFCC> <b>Customer Support</b></td></tr> <tr></tr></table></div><br /><table width="100%" align="center" border="0"> <tr><td><font size="2"><div class="seperator"></div><div class="boardcontainer"><table cellpadding="4" cellspacing="1" border="0" width="100%"><tr><td colspan="6" class="catbg" height="18" >Unverified Numbers Database</td></tr><tr> <td class="windowbg" width="28%" align="center">Company Name</td> <td class="windowbg" width="12%" align="center">0870 / 0871</td> <td class="windowbg" width="12%" align="center">0844 / 0845</td> <td class="windowbg" width="12%" align="center">01 / 02 / 03</td> <td class="windowbg" width="12%" align="center">Freephone</td> <td class="windowbg" width="24%" align="center">Other Information</td></tr><td class=windowuv width=28% align=center BGCOLOR=#CCFFFF> Microsoft</td><td class=windowuv width=12% align=center BGCOLOR=#CCFFFF> 0870 501 0800</a></td><td class=windowuv width=12% align=center BGCOLOR=#CCFFFF> 0844 800 8338</a></td><td class=windowuv width=12% align=center BGCOLOR=#CCFFFF> 0118 909 7994</a></td><td class=windowuv width=12% align=center BGCOLOR=#CCFFFF> </a></td><td class=windowuv width=24% align=center BGCOLOR=#CCFFFF> <b>Premier Support</b></td></tr> <tr><td class=windowuv width=28% align=center BGCOLOR=#CCFFFF>Microsoft AskPartner (Licensing)</a></td><td class=windowuv width=12% align=center BGCOLOR=#CCFFFF> 0870 607 0700</a></td><td class=windowuv width=12% align=center BGCOLOR=#CCFFFF> </a></td><td class=windowuv width=12% align=center BGCOLOR=#CCFFFF> 020 8784 1000</a></td><td class=windowuv width=12% align=center BGCOLOR=#CCFFFF> </a></td><td class=windowuv width=24% align=center BGCOLOR=#CCFFFF> Switchboard of Sitel UK in Kingston where the AskPartner team is based. Ask for Microsoft Team. 0800 - 1800.</td></tr> <tr><td class=windowuv width=28% align=center BGCOLOR=#CCFFFF> Microsoft Office Live Meeting</td><td class=windowuv width=12% align=center BGCOLOR=#CCFFFF> </a></td><td class=windowuv width=12% align=center BGCOLOR=#CCFFFF> </a></td><td class=windowuv width=12% align=center BGCOLOR=#CCFFFF> 020 3024 9260</a></td><td class=windowuv width=12% align=center BGCOLOR=#CCFFFF> 0800 0854811</a></td><td class=windowuv width=24% align=center BGCOLOR=#CCFFFF> EMC Conferencing on Meeting Place</td></tr></tr></table></div><br /><center><a href="http://homephone.consumerchoices.co.uk/?partner=saynoto0870" target="_blank"><img src="/banners/consumerchoices.png" border="0" alt="ConsumerChoices" align="middle"></img></a><BR><BR></center><div class="seperator"><table cellpadding="4" cellspacing="1" border="0" width="100%"><tr> <td class="titlebg" align="center" colspan="2"> Info Centre </td></tr> <td class="windowbg2"> <div style="float: left; width: 59%; text-align: left;"> <span class="small">Please use the Contact Us option, to report any incorrect numbers that you notice on the site. Thanks for your support.</span><br /> </div> <div style="float: left; width: 40%; text-align: left;"> <div class="small" style="float: left; width: 49%;"><span style="color: red;"><b>lllll</b></span> Main Database - A number that has been checked and at the time it was checked worked correctly. Please let us know of any numbers that no longer work as expected.</div><div class="small" style="float: left; width: 49%;"><span style="color: #CCFFFF;"><b>lllll</b></span> Unverified Number - A number that has been added by a visitor to the website, and hasn't yet been verified as correct. Please use the Contact Us link at the top of the page to let us know if these work (or don't work) for you.</div> </div> </td></tr></table></div> </font></td> </tr></table><br><head><style><!--.smallfont{ font: 11px verdana, geneva, lucida, 'lucida grande', arial, helvetica, sans-serif;}--></style></head><b><center><font color='red'></center></b></font><BR><center><script type="text/javascript"><!--google_ad_client = "pub-9959843696187618";google_ad_width = 728;google_ad_height = 90;google_ad_format = "728x90_as";google_ad_type = "text_image";//2007-06-07: SAYNOTO0870-Footergoogle_ad_channel = "7459969292";google_color_border = "FFFFE6";google_color_bg = "FFFFE6";google_color_link = "32527A";google_color_text = "000000";google_color_url = "2D8930";//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script><BR></center><BR><center><B><font face="Tahoma" size="2">Website and Content © 1999-2011 SAYNOTO0870.COM. All Rights Reserved</b>.<br><b>Written permission is required to duplicate any of the content within this site. </b></center></font><script src="http://www.google-analytics.com/urchin.js" type="text/javascript"></script><script type="text/javascript">_uacct = "UA-194609-1";urchinTracker();</script></body></html> 解决方案 The following XPATH allows you to search for a specific DIV (with the class 'boardcontainer') within your HTML document://div[@class='boardcontainer']/tableTo handle empty rows, simply check whether or not the returned HtmlNodeCollection is null.Here is a complete example:HtmlDocument htmlDoc = new HtmlDocument();htmlDoc.LoadHtml(html);foreach (HtmlNode table in htmlDoc.DocumentNode.SelectNodes("//div[@class='boardcontainer']/table")){ Console.WriteLine("Found: " + table.Id); foreach (HtmlNode row in table.SelectNodes("tr")) { Console.WriteLine("row"); HtmlNodeCollection cells = row.SelectNodes("th|td"); if (cells == null) { continue; } foreach (HtmlNode cell in cells) { Console.WriteLine("cell: " + cell.InnerText); } }}You should also check if a table is found and if the found table contains rows at all. 这篇关于HtmlAgilityPack - 从html表中获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-10 23:02