Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/310.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Xpath找不到下一个元素_C#_Html_Asp.net_Xpath_Html Table - Fatal编程技术网

C# Xpath找不到下一个元素

C# Xpath找不到下一个元素,c#,html,asp.net,xpath,html-table,C#,Html,Asp.net,Xpath,Html Table,我对xpath有问题;这是我的html数据: <table id="availabilityTable0" class="w99 availabilityTable"> <tr> <th scope="col" class="center">Waktu</th> <th scope="col" class="ce

我对xpath有问题;这是我的html数据:

              <table id="availabilityTable0" class="w99 availabilityTable">
                <tr>
                  <th scope="col" class="center">Waktu</th>
                  <th scope="col" class="center">Keberangkatan /
              Tiba</th>
                  <th scope="col" class="center">Penerbangan</th>
                  <th scope="col" class="center">Harga Promo</th>
                  <th scope="col" class="center">Harga Normal</th>
                </tr>
                <tr class="altRowItem">
                  <td class="center">7:00 <BR>8:20 </td>
                  <td class="center">Batam<BR>Kuala Namu</td>
                  <td class="center">QG 

            885</td>
                  <td class="fareCol1"></td>
                  <td class="fareCol2">
                    <p><input id="ControlGroupScheduleSelectView_AvailabilityInputScheduleSelectView_RadioButtonMkt1Fare4" type="radio" name="ControlGroupScheduleSelectView$AvailabilityInputScheduleSelectView$market1" value="0~Q~~Q~RGFR~~1~X|QG~ 885~ ~~BTH~05/19/2014 07:00~KNO~05/19/2014 08:20~">Rp.365,000
                      ( Q/Cls;
                    4 )
                  </p>
                    <p><input id="ControlGroupScheduleSelectView_AvailabilityInputScheduleSelectView_RadioButtonMkt1Fare5" type="radio" name="ControlGroupScheduleSelectView$AvailabilityInputScheduleSelectView$market1" value="0~P~~P~RGFR~~1~X|QG~ 885~ ~~BTH~05/19/2014 07:00~KNO~05/19/2014 08:20~">Rp.395,000
                      ( P/Cls;
                    4 )
                  </p>
                  <p>&nbsp;</p></td>
                </tr>
                <tr class="trSSRMarketControlGroupScheduleSelectView_AvailabilityInputScheduleSelectView_RadioButtonMkt1Fare17">
                  <td colspan="5">
                    <div>
                      <table>
                        <tr>
                          <td colspan="5">
                            <div class="FareRulesTable-Normal-Left-AI">
                              <table>
                                <tr>
                                  <td>
                                    <h3>Fare Rules:</h3>ccc</td>
                                </tr>
                                <tr>
                                  <td>ccc</td>
                                </tr>
                                <tr></tr>
                              </table>
                            </div>
                          </td>
                        </tr>
                      </table>
                    </div>
                  </td>
                </tr>
                <tr class="trSSRMarketControlGroupScheduleSelectView_AvailabilityInputScheduleSelectView_RadioButtonMkt1Fare4">
                  <td colspan="5">
                    <div>
                      <table>
                        <tr>
                          <td colspan="5">
                            <div class="FareRulesTable-Normal-Left-AI">
                              <table>
                                <tr>
                                  <td><h3>Fare Rules:</h3>ccc</td>
                                </tr>
                                <tr>
                                  <td>ccc</td>
                                </tr>
                                <tr></tr>
                              </table>
                            </div>
                          </td>
                        </tr>
                      </table>
                    </div>
                  </td>
                </tr>
                <tr>
                  <td class="center">16:55 <BR>18:15 </td>
                  <td class="center">Batam<BR>Kuala Namu</td>
                  <td class="center">QG 

            883</td>
                  <td class="fareCol1"></td>
                  <td class="fareCol2">
                    <p><input id="ControlGroupScheduleSelectView_AvailabilityInputScheduleSelectView_RadioButtonMkt1Fare18" type="radio" name="ControlGroupScheduleSelectView$AvailabilityInputScheduleSelectView$market1" value="0~P~~P~RGFR~~1~X|QG~ 883~ ~~BTH~05/19/2014 16:55~KNO~05/19/2014 18:15~">
                      Rp.795,000
                      ( P/Cls;
                    4 )
                  </p>
                    <p><input id="ControlGroupScheduleSelectView_AvailabilityInputScheduleSelectView_RadioButtonMkt1Fare19" type="radio" name="ControlGroupScheduleSelectView$AvailabilityInputScheduleSelectView$market1" value="0~O~~O~RGFR~~1~X|QG~ 883~ ~~BTH~05/19/2014 16:55~KNO~05/19/2014 18:15~">
                      Rp.820,000
                      ( O/Cls;
                    4 )
                  </p>
                  <p>&nbsp;</p></td>
                </tr>
                <tr class="trSSRMarketControlGroupScheduleSelectView_AvailabilityInputScheduleSelectView_RadioButtonMkt1Fare30">
                  <td colspan="5">
                    <div>
                      <table>
                        <tr>
                          <td colspan="5">
                            <div class="FareRulesTable-Normal-Left-AI">
                              <table>
                                <tr>
                                  <td>
                                    <h3>Fare Rules:</h3>abc</td>
                                </tr>
                                <tr>
                                  <td>abc</td>
                                </tr>
                                <tr></tr>
                              </table>
                            </div>
                          </td>
                        </tr>
                      </table>
                    </div>
                  </td>
                </tr>
                <tr class="trSSRMarketControlGroupScheduleSelectView_AvailabilityInputScheduleSelectView_RadioButtonMkt1Fare18">
                  <td colspan="5">
                    <div>
                      <table>
                        <tr>
                          <td colspan="5">
                            <div class="FareRulesTable-Normal-Left-AI">
                              <table>
                                <tr>
                                  <td>
                                    <h3>Fare Rules:</h3>abc</td>
                                </tr>
                                <tr>
                                  <td>abc</td>
                                </tr>
                                <tr></tr>
                              </table>
                            </div>
                          </td>
                        </tr>
                      </table>
                    </div>
                  </td>
                </tr>
              </table>
如果要排很长的队,我很抱歉。。从这个html中,呈现应该类似于不重要视图的剪切:

<radiobutton>Rp.365,000 ( Q/Cls; 4 ) 
<radiobutton>Rp.395,000 ( P/Cls; 4 )

<radiobutton>Rp.795,000 ( P/Cls; 4 )
<radiobutton>Rp.820,000 ( O/Cls; 4 )
但我希望它是这样的:

<radiobutton>Rp.365,000 ( Q/Cls; 4 ) ---- <radiobutton>Rp.395,000 ( P/Cls; 4 )
<radiobutton>Rp.795,000 ( P/Cls; 4 ) ---- <radiobutton>Rp.820,000 ( O/Cls; 4 )
所有价格均为基于表Availability Table0的fareCol2 td元素。。从我的代码中,我可以从第一个td fareCol2获取所有输入元素,但下一个fareCol2得到null

HtmlDocument doc = new HtmlDocument();
        DataTable dt = new DataTable();
        string htmldata = "";
        string removeClassFare = string.Empty;
        int index;

        doc.LoadHtml(html);
        var searchAvaibilityTable = doc.DocumentNode.SelectNodes(".//table[contains(@id, 'availabilityTable')]");
        var searchAvaibilityTable1 = doc.DocumentNode.SelectNodes(".//table[contains(@id, 'availabilityTable0')]//td[@class='fareCol2']");

        var searchAvaibilityTable2 = doc.DocumentNode.SelectNodes(".//table[@id='availabilityTable0']//tr[2]//td[@class='fareCol2']//input");

        for (int i = 0; i < searchAvaibilityTable2.Count; i++)
        {

            try
                {
                    index = searchAvaibilityTable2[i].ParentNode.InnerText.IndexOf("(");
                    if (index != -1)
                    {
                        removeClassFare = searchAvaibilityTable2[i].ParentNode.InnerText.Substring(0, index);
                        removeClassFare = System.Text.Encoding.ASCII.GetString(System.Text.Encoding.ASCII.GetBytes(removeClassFare)).Replace("??", "").Replace("Rp.", "").Trim();
                    }
                    else
                    {
                        removeClassFare = searchAvaibilityTable2[i].ParentNode.InnerText;
                    }
                }
                catch (Exception e)
                {
                    removeClassFare = searchAvaibilityTable2[i].ParentNode.InnerText;
                }

            htmldata = htmldata + "<input <input onclick='faredetail(this.value, this.name)' id=\"" + searchAvaibilityTable2[i].Attributes["id"].Value + "\" type=\"radio\" value=\"" + searchAvaibilityTable2[i].Attributes["value"].Value + "\" name=\"" + searchAvaibilityTable2[i].Attributes["name"].Value + "\"><br>" + removeClassFare + " # ";
        }

        return htmldata;
        //return searchAvaibilityTable.Count.ToString() + "-" + searchAvaibilityTable1.Count.ToString() + "-" + searchAvaibilityTable2.Count.ToString();
    }

这段代码,我可以得到第一个fareCol2,如何得到下一个fareCol2,这样我就可以得到我想要的视图?

在哪里可以得到空值?当我使用count..var searchAvailabilityTable2=doc.DocumentNode.SelectNodes//表[@id='availabilityTable0']//tr[2]//td[@class='fareCol2']//输入;可以,但是当我使用var searchAvailabilityTable2=doc.DocumentNode.SelectNodes//表[@id='availabilityTable0']//tr[2]//td[@class='fareCol2']][3]//input;`然后SearchAvailabilityTable2.count,我得到了空值,我不知道如何得到下一个票价2,我只能得到第一个票价2类@Marcus Rickerttd[@cla‌​ss='fareCol2'][3]不会带你去下一个,而是去下一个。同意马库斯的观点,那么td[@cla]呢‌​ss='fareCol2'][2]?