Когда я использую XPath для извлечения данных, он не дает никакого ответа в messagebox.show - PullRequest
0 голосов
/ 22 ноября 2018

Любой может помочь мне, я использую Copy Xpath в Google Chrome Tools для разработки этого пути:

/html/body/table/tbody/tr/td/table[2]/tbody/tr/td/table[1]/tbody/tr[1]/td[2]/table[2]/tbody/tr[1]/td/div[2]/div[1]/table/tbody/tr/td/table/tbody/tr[2]/td[1]

и я использую путь в этом коде для получения данных:

HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();

        doc.LoadHtml(webBrowser1.Document.GetElementById("tablemasterbleue").InnerHtml);

        int i = 2;
        while (doc.DocumentNode.SelectSingleNode("/html/body/table/tbody/tr/td/table[2]/tbody/tr/td/table[1]/tbody/tr[1]/td[2]/table[2]/tbody/tr[1]/td/div[2]/div[1]/table/tbody/tr/td/table/tbody/tr[" + i + "]/td[1]") != null)
        {
            string Code_de_ligne = "";
            string Numero_de_produit = doc.DocumentNode.SelectSingleNode("/html/body/table/tbody/tr/td/table[2]/tbody/tr/td/table[1]/tbody/tr[1]/td[2]/table[2]/tbody/tr[1]/td/div[2]/div[1]/table/tbody/tr/td/table/tbody/tr[" + i + "]/td[1]").InnerText;
            string Desc_prod = doc.DocumentNode.SelectSingleNode("//tbody/tr[" + i + "]/td[5]/span").InnerText;
            string Prix_coutânt = doc.DocumentNode.SelectSingleNode("//tbody/tr[" + i + "]/td[7]/span[2]").InnerText;
            string Prix_de_vente = "";
            string Qte = doc.DocumentNode.SelectSingleNode("//tbody/tr[" + i + "]/td[6]/input").GetAttributeValue("value", "");

            i++;

            MessageBox.Show(Code_de_ligne + "|" + Numero_de_produit + "|" + Desc_prod + " | " + Prix_coutânt + "|" + Prix_de_vente + "|" + Qte);
        }

, но он не дает никакого ответа в MessageBox.Show.

Я выполняю XPath для этого HTML-документа:

<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Provincial Tire</title>
<link rel="shortcut icon" href="http://www.provincialtire.net/provt/images/plugin/favicon.ico">
<link href="/designglobal/inosoft/style.css" rel="stylesheet" type="text/css">



<link href="http://www.provincialtire.net/jquery/css/imgpreview.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="http://www.provincialtire.net/jquery/css/thickbox.css" type="text/css" media="screen">
<link href="http://www.provincialtire.net/jquery/css/uploadify.css" rel="stylesheet" type="text/css">
<link href="http://www.provincialtire.net/jquery/css/style.css" rel="stylesheet" type="text/css">


<script type="text/javascript" src="http://www.provincialtire.net/jquery/js/jquery-1.3.2.min.js"></script> 
<script type="text/javascript" src="http://www.provincialtire.net/jquery/js/jquery-ui-1.7.2.custom.min.js"></script>


<script type="text/javascript" src="http://www.provincialtire.net/jquery/js/jquery.tablesorter2.min.js"></script> 





<script type="text/javascript" src="http://www.provincialtire.net/jquery/js/jquery-thickbox.js"></script>






<script type="text/javascript" src="http://www.provincialtire.net/jquery/js/jquery.tooltips.js"></script>




<script type="text/javascript" src="http://www.provincialtire.net/jquery/js/jquery.imgpreview.js"></script>




<script type="text/javascript" src="http://www.provincialtire.net/jquery/js/jquery.uploadify.v2.1.0.js"></script>
<script type="text/javascript" src="http://www.provincialtire.net/jquery/js/swfobject.js"></script>














<script type="text/javascript">




        function envoieRequete(url,id)
        {
            var xhr_object = null;
            var position = id;

               if(window.XMLHttpRequest)  xhr_object = new XMLHttpRequest();
              else
                if (window.ActiveXObject)  xhr_object = new ActiveXObject("Microsoft.XMLHTTP"); 

            // On ouvre la requete vers la page désirée
            xhr_object.open("GET", url, true);


            document.getElementById(position).innerHTML = "<center><img src=\"http://www.provincialtire.net/provt/images/load.gif\" ><\/center>";


            xhr_object.onreadystatechange = function(){
            if ( xhr_object.readyState == 4 )
            {

                // j'affiche dans la DIV spécifiées le contenu retourné par le fichier
                document.getElementById(position).innerHTML = xhr_object.responseText;



            }
            }
            // dans le cas du get


            xhr_object.send(null);

        }
 </script>















<script type="text/javascript">


function pausecomp(millis) 
{
var date = new Date();
var curDate = null;

do { curDate = new Date(); } 
while(curDate-date < millis);
} 





        function envoieRequeteWait(url,id)
        {

            pausecomp(5);

            var xhr_object = null;
            var position = id;

               if(window.XMLHttpRequest)  xhr_object = new XMLHttpRequest();
              else
                if (window.ActiveXObject)  xhr_object = new ActiveXObject("Microsoft.XMLHTTP"); 

            // On ouvre la requete vers la page désirée
            xhr_object.open("GET", url, true);


            document.getElementById(position).innerHTML = "<center><img src=\"http://www.provincialtire.net/provt/images/load.gif\" ><\/center>";


            xhr_object.onreadystatechange = function(){
            if ( xhr_object.readyState == 4 )
            {

                // j'affiche dans la DIV spécifiées le contenu retourné par le fichier
                document.getElementById(position).innerHTML = xhr_object.responseText;



            }
            }
            // dans le cas du get


            xhr_object.send(null);

        }
 </script>














<script type="text/javascript">

function envoieRequeteSearch(url,id)
        {
 var sid = "2nmia7njlrrc8a9mn5199do5d5";  
            var xhr_object = null;
            var position = id;

               if(window.XMLHttpRequest)  xhr_object = new XMLHttpRequest();
              else
                if (window.ActiveXObject)  xhr_object = new ActiveXObject("Microsoft.XMLHTTP"); 

            // On ouvre la requete vers la page désirée
            xhr_object.open("GET", url, true);
            xhr_object.setRequestHeader('Set-Cookie', 'PHPSESSID=' + sid); 

            document.getElementById(position).innerHTML = "<br><br><table align=\"center\" border=\"0\" height=\"250\" width=\"350\" style=\"background-image:url(/designglobal/inosoft/loading_box.png)\"><tr><td align=\"center\"><img src=\"http://www.provincialtire.net/provt/images/plugins/logoajaxc.gif\" ><br><br><b>Please be patient....<\/b><br><\/td><\/tr><\/table><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>";


            xhr_object.onreadystatechange = function(){
            if ( xhr_object.readyState == 4 )
            {


                // j'affiche dans la DIV spécifiées le contenu retourné par le fichier
                document.getElementById(position).innerHTML = xhr_object.responseText;















              $(document).ready(function() { 
                  $("table").tablesorter({ 
                      // pass the headers argument and assing a object 
                      headers: { 
                          // assign the secound column (we start counting zero) 
                          9: { 
                              // disable it by setting the property sorter to false 
                              sorter: false 
                          },                      
                            // assign the third column (we start counting zero) 
                          8: { 
                              // disable it by setting the property sorter to false 
                              sorter: false 
                          } 
                      }

                  }); 
              });




                $(document).ready(function() { 
                /*$('a#first').imgPreview();*/
                $('a#first').imgPreview({
                    imgCSS: { width: 250 }
                }); });





            }
            }
            // dans le cas du get



            xhr_object.send(null);

        }
 </script>
















<script type="text/javascript">

function Requete(url,id)
        {
 var sid = "2nmia7njlrrc8a9mn5199do5d5";  
            var xhr_object = null;
            var position = id;

               if(window.XMLHttpRequest)  xhr_object = new XMLHttpRequest();
              else
                if (window.ActiveXObject)  xhr_object = new ActiveXObject("Microsoft.XMLHTTP"); 

            // On ouvre la requete vers la page désirée
            xhr_object.open("GET", url, true);
            xhr_object.setRequestHeader('Set-Cookie', 'PHPSESSID=' + sid); 

            document.getElementById(position).innerHTML = "<img src=\"http://www.provincialtire.net/provt/images/pbar.gif\" >";


            xhr_object.onreadystatechange = function(){
            if ( xhr_object.readyState == 4 )
            {


                // j'affiche dans la DIV spécifiées le contenu retourné par le fichier
                document.getElementById(position).innerHTML = xhr_object.responseText;

            }
            }
            // dans le cas du get



            xhr_object.send(null);

        }
 </script>










<script type="text/javascript"> 

function stopRKey(evt) { 
  var evt = (evt) ? evt : ((event) ? event : null); 
  var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null); 
  if ((evt.keyCode == 13) && (node.type=="text"))  {return false;} 
} 

document.onkeypress = stopRKey; 

</script>





<script type="text/javascript">


function toggle(anId)
{
    node = document.getElementById(anId);
    if (node.style.visibility=="hidden")
    {
        // caché vers montrer
        node.style.visibility = "visible";
        node.style.height = "auto";         
    }
    else
    {
        // visible vers cacher
        node.style.visibility = "hidden";
        node.style.height = "0";            
    }
}

</script>





<script type="text/javascript">
        function blocknumber(event) {
        // Compatibilité IE / Firefox
        if(!event&&window.event) {
        event=window.event;
        }
        // IE
        if(event.keyCode < 48 || event.keyCode > 57) {
        event.returnValue = false;
        event.cancelBubble = true;
        }
        // DOM
        if(event.which < 48 || event.which > 57) {
        event.preventDefault();
        event.stopPropagation();
        }
        }   




function blockletter(evt) {
    var e = evt || window.event;
    var key = e.keyCode || e.which;

    if (!e.shiftKey && !e.altKey && !e.ctrlKey &&
    // numbers   
    key >= 48 && key <= 57 ||
    // Numeric keypad
    key >= 96 && key <= 105 ||
    // Backspace and Tab and Enter
    key == 8 || key == 9 || key == 13 ||
    // Home and End
    key == 35 || key == 36 ||
    // left and right arrows
    key == 37 || key == 39 ||
    // Del and Ins
    key == 46 || key == 45 ||
    // point .
    key == 110) {
        // input is VALID
    }
    else {
        // input is INVALID
        e.returnValue = false;
        if (e.preventDefault) e.preventDefault();
    }
}

</script>    



<script type="text/JavaScript">
<!--
function timedRefresh(timeoutPeriod) {
    theUrl = 'http://www.provincialtire.net/search.html';

    setTimeout("location.replace(theUrl);",timeoutPeriod);
}
//  JavaScript:timedRefresh(1000000); -->
</script>




<script>
function SendInfo(e){

    if(e){
        e = e 
        } else {
        e = window.event
    } 

    if(e.which){ 
    var keycode = e.which
    } else {
    var keycode = e.keyCode 
    }

    if(keycode == 13) { 
         envoieRequeteSearch('modules/searchajax.php?size='+form1.size.value+'&manu='+form1.manu.value+'&desc='+form1.desc.value+'&type='+form1.type.value+'&nostock='+form1.nostock.checked+'&prodno='+form1.prodno.value+'&tri='+form1.tri.value+'&cache='+form1.cache.checked,'conteneur');      

    }

}
</script>

















<script type="text/javascript">if (window != top) top.location.href = location.href;</script>
<noscript>
You do Activate JavaScript on your Brwoser / Vous devez activer le JavaScript de votre navigateur
</noscript>


</head>

<body onload=" ">





<table width="960" border="0" align="center">
  <tbody><tr>
    <td>


    <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
                <tbody><tr>
          <td valign="top">


          <table width="100%" border="0" cellspacing="0" cellpadding="0" style="background-image:url(http://www.provincialtire.net/provt/images/plugins/toplogo.jpg)">
            <tbody><tr>
              <td>&nbsp;</td>
              <td>&nbsp;</td>
              <td>&nbsp;</td>
              <td width="392" height="110">

          <div style="position:relative;">

            <div style="position:absolute; bottom:35px; right:5px;">
              <a href="exit-en.html"> <img src="http://www.provincialtire.net/images/error.png" title="Exit"> </a>
            </div>

         </div>                    


                </td>
              </tr>
            </tbody></table>

           </td>
        </tr>
      </tbody></table>


      <table width="960" border="0" align="center" cellpadding="0" cellspacing="0">
        <tbody><tr>
          <td valign="top" background="/designglobal/inosoft/background.jpg" style="background-repeat:no-repeat;" bgcolor="#ffffff">
















        <div style="position:relative; top:-5px;">

          <table style="background-image:url(/designglobal/inosoft/top_menu_button.jpg)" border="0" cellspacing="0" cellpadding="0" height="45" id="cellule_menu_principal">
            <tbody><tr>


              <td width="50" align="center" class="menu_principal">&nbsp;   </td>

              <td width="96" align="center" class="menu_principal">                 <a style="" href="/">Informations</a>  </td>

              <td width="96" align="center" class="menu_principal">             <a style="" href="promotions-en.html">Promotions</a> </td>

              <td width="96" align="center" class="menu_principal">             <a style="color:#FF0000" href="search-en.html">Search <br> Products</a> </td>

              <td width="96" align="center" class="menu_principal">                 <a style="" href="acount-en.html">Your Account</a> </td>

              <td width="96" align="center" class="menu_principal">             <a style="" href="storage-en.html">Your<br>Storage</a> </td>

              <td width="96" align="center" class="menu_principal">
              &nbsp;              
              </td>

              <td width="96" align="center" class="menu_principal">                  <a style="" href="tracking-en.html">Track Shipments</a> </td>

              <td width="96" align="center" class="menu_principal">             <a style="" href="tools-en.html">Tools</a> </td>

              <td width="80" align="center" class="menu_principal"><a href="modules/rma.php?l=en&amp;noclient=73742&amp;keepThis=true&amp;TB_iframe=true&amp;height=350&amp;width=475" title="RMA" class="thickbox">
                              RMA              </a></td>

              <td width="96" align="center" class="menu_principal">                  <a style="" href="contact-en.html">Contact Us</a> </td>
            </tr>


          </tbody></table>

        </div> 


















            <table width="100%" height="1000" border="0" cellpadding="0" cellspacing="0">
              <tbody><tr>
              <td width="15">&nbsp;</td>
              <td class="texte" valign="top"><br>












          <table width="100%" border="0" cellpadding="0">
            <tbody><tr>
              <td width="120">



              <table height="36" border="0" cellpadding="0" cellspacing="0" background="http://www.provincialtire.net/provt/images/topbutton/img_fond_titre.jpg">
                <tbody><tr>
                  <td valign="middle" class="titre"><img src="http://www.provincialtire.net/provt/images/topbutton/img_cote_gauche_titre.jpg" width="12" height="39"></td>
                  <td valign="top" class="titre"><table border="0" cellspacing="0" cellpadding="0">
                      <tbody><tr>
                        <td height="5"></td>
                      </tr>
                      <tr>
                        <td>

                        Order                        
                        </td>
                      </tr>
                  </tbody></table></td>
                  <td width="16" align="right" valign="middle"><img src="http://www.provincialtire.net/provt/images/topbutton/img_cote_droit_titre.jpg" width="12" height="39"></td>
              </tr>
            </tbody></table>


            </td>


              <td>&nbsp;











              </td>





            </tr>
          </tbody></table>






<br>




<table width="100%" cellpadding="4" cellspacing="4"><tbody><tr><td>
















<div class="dialog"> <div class="boxContent"> <div class="t"></div> 






<a style="color:#FFFFFF" href="/?ordernow=y&amp;rem=all">Delete All Products</a>



&nbsp;



</div> <div class="b"> <div> </div> </div> </div> 
















<div class="dialog"> <div class="boxContent"> <div class="t"></div> 






<table border="1" cellpadding="0" cellspacing="0" bordercolor="#FFD700" width="100%"><tbody><tr valign="top"><td valign="top">  

 &nbsp;&nbsp;<br><table class="tablemasterbleue" style="font-size:11px;" width="100%" border="0" cellpadding="0" cellspacing="0">
    <tbody><tr class="headerlist">
        <td width="100" align="center">Prod #</td>
        <td width="100" align="center">Manufacturer</td>
        <td width="75" align="center">Qty</td>
        <td width="35"></td>
        <td width="35"></td>
        <td width="">Description</td>
        <td width="35"></td>
        <td width="100" align="center">Price</td>
    </tr>


        <tr style="padding: 0px 10px 0px 10px; color:#000000; height:40px;" bgcolor="#EDEDED">
            <td align="left" width="125">&nbsp; <a href="/?ordernow=y&amp;rem=order&amp;prod=1"><img src="http://www.provincialtire.net/images/redcross.png"></a> &nbsp; 00959</td>
            <td align="center"><img title="" width="75" height="27" src="http://www.provincialtire.net/provt/images/plugins/logo/UNIR.gif"></td>
            <td align="center"> 4 </td>
            <td align="left">-</td><td> <img width="30" src="http://www.provincialtire.net/provt/images/plugins/type/W.png"> </td>
                <td align="left">&nbsp;&nbsp;205/60R16 Tiger Paw Ice &amp; Snow 3 </td>
            <td align="right"><div id="each1"><b></b></div></td><td style="background-image:url(/images/special.gif); background-repeat:no-repeat; background-position:top" align="center"><b>95.00</b></td>
    </tr><tr class="headerlist"><td colspan="8">

        <table width="100%" style="font-size:12px; font-weight:bold;" border="0">
            <tbody><tr style="color:#FFFFFF">
                <td colspan="3">&nbsp;</td>
                <td width="50">HST</td>
                <td width="25">

                <div id="tps">

                49.4                
                </div>



                </td>
            </tr>
            <tr style="color:#FFFFFF">
                <td colspan="3">&nbsp;</td>
                <td width="50"></td>
                <td width="25">


                <div id="tvq">





                </div>


                </td>
            </tr>
            <tr style="color:#FFFFFF">
                <td colspan="3">&nbsp;</td>
                <td width="50">TOTAL</td>
                <td width="25">
                    <div id="total">
                        429.4                
                    </div>
                </td>
            </tr>
        </tbody></table>

    </td></tr>

</tbody></table>






</td></tr></tbody></table>


<br><br>






</div> <div class="b"> <div> </div> </div> </div> 

</td></tr>

<tr><td>


</td></tr>

<tr><td>
<form id="form1" name="form1" method="post" action="/sendorder-en.html">

<div class="dialog"> <div class="boxContent"> <div class="t"></div>  


 <table style="color:#FFFFFF" width="100%" border="0" cellpadding="3" cellspacing="5">


          <tbody><tr>
            <td colspan="2" align="right">




              <br><b>This order does not apply to a national account<b><br><input type="hidden" value="n" name="clinat" id="clinat">       






               </b></b></td>
            </tr>


            <tr>
              <td>&nbsp;</td>
              <td>&nbsp;</td>
            </tr>
            <tr>
              <td width="50%"><b>Delivery Instruction: </b></td>
              <td width="50%"><input type="hidden" value="y" name="basketsend" id="basketsend"><input type="hidden" value="y" name="type" id="type"></td>
              </tr>
            <tr>
              <td rowspan="3" align="left" valign="top"><label>
                <input name="instruction" type="text" id="instruction" value="" maxlength="68" size="50">
              </label></td>
            <td align="right">



    <table cellpadding="3" cellspacing="3" border="0">
      <tbody><tr>
         <td align="right">
            <input type="radio" name="radio" id="radio" value="radio1" checked="checked">Next delivery 
            <input type="radio" name="radio" id="radio" value="radio2">Morning 
            <input type="radio" name="radio" id="radio" value="radio3">Afternoon    
        </td>
        </tr>

        <tr>
         <td align="right">   
             <input type="radio" name="radio" id="radio" value="radio4">Tomorrow Morning                
             <input type="radio" name="radio" id="radio" value="radio5">Tomorrow Afternoon   
          </td>
          </tr><tr>
          <td align="right">   
             <input type="radio" name="radio" id="radio" value="radio8">Standard Delivery                   
             <input type="radio" name="radio" id="radio" value="radio9">Urgent delivery  
          </td>
          </tr><tr> 
          <td align="right">   
             <input type="radio" name="radio" id="radio" value="radio6">Pick Up                 
              <input type="radio" name="radio" id="radio" value="radio7">See Special Instruction   
          </td>
      </tr>
    </tbody></table>            



    </td>
          </tr>
            <tr>
              <td align="right">&nbsp;</td>
          </tr>
            <tr>
              <td align="right">Purchase Order : 
                <label>
                  <input type="text" name="boncom" id="boncom" maxlength="10">
              </label></td>
              </tr>
            <tr>
              <td align="right">&nbsp;</td>
              <td align="right">&nbsp;</td>
          </tr>
            <tr>
              <td align="right">&nbsp;</td>
              <td align="right"><input class="normal" width="300px" type="submit" name="buttonsend" id="buttonsend" value="Send" onclick="javascript:this.disabled=true;form1.submit();"></td>
              </tr>
        </tbody></table>
</div> <div class="b"> <div> </div> </div> </div>  </form>
</td></tr></tbody></table>
<br>

<script>
$(document).ready(function() { 
/*$('a#first').imgPreview();*/
$('a#first').imgPreview({
    imgCSS: { width: 250 }
}); });

</script>                <br></td>
              <td width="15">&nbsp;</td>
            </tr>
            <tr>
              <td>&nbsp;</td>
              <td align="center">&nbsp;</td>
              <td>&nbsp;</td>
            </tr>
          </tbody></table>
            <table width="960" cellspacing="0" cellpadding="0" class="tablemasterbleueborder" border="3">

              <tbody><tr>
                <td height="36" align="center" valign="middle" bgcolor="#ffffff">

                <table width="100%">
                  <tbody><tr>
                    <td align="center">
                    <a href="http://www.inosoft.ca/english/index.htm"> <img src="images/inosoft-en.jpg" width="125" height="35" alt="InoSoft"> </a>
                    </td>
                  </tr>
                </tbody></table>
                </td>
              </tr>
          </tbody></table></td>
        </tr>
      </tbody></table>
      <br>
      <center>
      <a href="exit-en.html" style="color:#000">Exit</a>
      </center>
    <br></td>
  </tr>
</tbody></table>
<div id="imgPreviewContainer" style="display: none;"><img style="width: 250px;"></div></body></html>

Вот также скриншот элемента проверки: https://i.imgur.com/o59X5wA.png enter image description here

Итак, я собираюсь использовать xpath или мне нужно другое решение?

Заранее спасибо.

Ответы [ 2 ]

0 голосов
/ 24 ноября 2018

tablemasterbleue - это class, а не id, и поскольку ни один метод GetElementsByClassName не извлекает источник страницы с помощью WebBrowser1.DocumentText, то выполняет цикл строк или tr.

, следующий xpath будет выбирать строкив классе таблицы tablemasterbleue, но пропустите, если есть класс headerlist, существующий сверху и снизу.

doc.LoadHtml(WebBrowser1.DocumentText);

foreach (var node in doc.DocumentNode
    .SelectNodes("//table[@class='tablemasterbleue']/tbody/tr[not(contains(@class, 'headerlist'))]"))
{
    string Code_de_ligne = "";
    string Numero_de_produit = node.SelectSingleNode("td[1]").InnerText;
    string Desc_prod = node.SelectSingleNode("td[6]").InnerText;
    string Prix_coutânt = node.SelectSingleNode("td[8]").InnerText;
    string Prix_de_vente = "";
    string Qte = node.SelectSingleNode("td[3]").InnerText;

    MessageBox.Show(Code_de_ligne + "|" + Numero_de_produit + "|" + Desc_prod + " | " + Prix_coutânt + "|" + Prix_de_vente + "|" + Qte);
}
0 голосов
/ 22 ноября 2018

Фактическая проблема заключается в том, что XPath запросов типа //tbody/tr[" + i + "]/td[5]/span возвращает ноль , поскольку отсутствует соответствующий элемент span HTML, и поэтому .InnerText аварийно завершает работу с NullReferenceException.Также индексы td элементов (например, td[5]), похоже, неверны.Правильный XPath равен //tbody/tr[" + i + "]/td[6].Но вы можете переписать свой код, чтобы сделать его намного лучше.

Поскольку вы хотите выполнять итерацию по нескольким узлам продукта, лучше использовать doc.DocumentNode.SelectNodes(), который возвращает набор всех совпадающих узлов (продуктов) вместо doc.DocumentNode.SelectSingleNode().Каждый выбранный узел продукта выглядит примерно так:

<tr style="padding: 0px 10px 0px 10px; color:#000000; height:40px;" bgcolor="#EDEDED">
    <td align="left" width="125">&nbsp; <a href="/?ordernow=y&amp;rem=order&amp;prod=1"><img src="http://www.provincialtire.net/images/redcross.png"></a> &nbsp; 00959</td>
    <td align="center"><img title="" width="75" height="27" src="http://www.provincialtire.net/provt/images/plugins/logo/UNIR.gif"></td>
    <td align="center"> 4 </td>
    <td align="left">-</td><td> <img width="30" src="http://www.provincialtire.net/provt/images/plugins/type/W.png"> </td>
    <td align="left">&nbsp;&nbsp;205/60R16 Tiger Paw Ice &amp; Snow 3 </td>
    <td align="right"><div id="each1"><b></b></div></td><td style="background-image:url(/images/special.gif); background-repeat:no-repeat; background-position:top" align="center"><b>95.00</b></td>
</tr>

Если этот узел уже выбран, вам не нужно снова выполнять сложный XPath запрос, например /html/body/table/tbody/tr/td/table[2]/tbody/tr/td/table[1]/tbody/tr[1]/td[2]/table[2]/tbody/tr[1]/td/div[2]/div[1]/table/tbody/tr/td/table/tbody/tr[" + i + "]/td[1], чтобы собрать нужные кускиинформации.Выполните запрос XPath только против выбранного ранее узла HTML, например, node.SelectSingleNode("td[1]"), который не только намного короче и удобочитаемее, но и более эффективен.Весь код может выглядеть следующим образом:

HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(webBrowser1.Document.GetElementById("tablemasterbleue").InnerHtml);

foreach(var node in doc.DocumentNode
    .SelectNodes("/html/body/table/tbody/tr/td/table[2]/tbody/tr/td/table[1]/tbody/tr[1]/td[2]/table[2]/tbody/tr[1]/td/div[2]/div[1]/table/tbody/tr/td/table/tbody/tr")
    .Skip(1)/*Skip first row containing headers*/)
{
    string Code_de_ligne = "";
    string Numero_de_produit = node.SelectSingleNode("td[1]").InnerText;
    string Desc_prod = node.SelectSingleNode("td[6]").InnerText;
    string Prix_coutânt = node.SelectSingleNode("td[8]").InnerText;
    string Prix_de_vente = "";
    string Qte = node.SelectSingleNode("td[3]").InnerText;

    MessageBox.Show(Code_de_ligne + "|" + Numero_de_produit + "|" + Desc_prod + " | " + Prix_coutânt + "|" + Prix_de_vente + "|" + Qte);
}

Поскольку полученные строки могут содержать избыточные объекты HTML и пробелы, например "&nbsp; &nbsp; 00959", вам может потребоваться удалить их:

// Convert string like "&nbsp;  &nbsp; 00959" to just "00959"
Numero_de_produit = HtmlEntity.DeEntitize(Numero_de_produit).Trim();
...