1

だから、私はコラムのテストを受けようとしていますTitle or Names or DateTime

td要素を取得しようとしてtestいますが、CSSSelectorを使用して次のことを試しました。

div#body-inner div#ctl00_ContentPlaceHolder1_Control1_pnlList div table#ctl00_ContentPlaceHolder1_Control1_gv.gv tbody tr.item td:nth-child(4)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head id="ctl00_PageHead">
  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  <title>Employee</title>

  <body id="ctl00_PageBody">
    <form name="aspnetForm">
      <div>
      </div>
      <div>
      </div>
      <table class="global-table" cellpadding="0" cellspacing="0">
        <tr class="body">
          <td>
            <div id="body">
              <div id="body-inner">
                <h1>
                                    Employee Information</h1>
                <div id="ctl00_ContentPlaceHolder1_Control1_pnlList" style="width: 100%;">
                  &nbsp;
                  <div class='filter'>
                  </div>
                  <div>
                    <table class="gv" cellspacing="0" border="0" id="ctl00_ContentPlaceHolder1_Control1_gv" style="border-collapse: collapse;">
                      <tr class="header">
                        <th class=" nolink" scope="col">
                          &nbsp;
                        </th>
                        <th scope="col">
                          <a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$Control1$gv','Sort$Phone')">
                                                        Phone</a>
                        </th>
                        <th class=" sorted-desc" scope="col">
                          <a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$Control1$gv','Sort$Title')">
                                                        Title</a>
                        </th>
                        <th scope="col">
                          <a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$Control1$gv','Sort$SubTitle')">
                                                        SubTitle</a>
                        </th>
                        <th scope="col">
                          <a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$Control1$gv','Sort$Names')">
                                                        Names</a>
                        </th>
                        <th scope="col">
                          <a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$Control1$gv','Sort$Names')">
                                                        Enames</a>
                        </th>
                        <th scope="col">
                          <a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$Control1$gv','Sort$Active')">
                                                        Active</a>
                        </th>
                        <th scope="col">
                          <a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$Control1$gv','Sort$DateTime')">
                                                        &nbsp;DateTime</a>
                        </th>
                      </tr>
                      <tr class="item">
                        <td align="center">
                          <a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$Control1$gv','Select$0')">
                                                        Edit</a>
                        </td>
                        <td align="center" style="width: 15px;">
                        </td>
                        <td>
                          Test
                        </td>
                        <td>
                          &nbsp;
                        </td>
                        <td>
                          &nbsp;
                        </td>
                        <td>
                          &nbsp;
                        </td>
                        <td>
                          &nbsp;
                        </td>
                        <td>
                          8/23/2011&nbsp;
                        </td>
                      </tr>
                      <tr class="altItem">
                        <td align="center">
                          <a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$Control1$gv','Select$1')">
                                                        Edit</a>
                        </td>
                        <td align="center" style="width: 15px;">
                        </td>
                        <td>
                          Test1
                        </td>
                        <td>
                          1
                        </td>
                        <td>
                          Employee
                        </td>
                        <td>
                          &nbsp;
                        </td>
                        <td>
                          &nbsp;
                        </td>
                        <td>
                          7/31/2014
                        </td>
                      </tr>
                      <tr class="item">
                        <td align="center">
                          <a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$Control1$gv','Select$2')">
                                                        Edit</a>
                        </td>
                        <td align="center" style="width: 15px;">
                        </td>
                        <td>
                          Test2</td>
                        <td>
                          111
                        </td>
                        <td>
                          Employer
                        </td>
                        <td>
                        </td>
                        <td>
                          &nbsp;
                        </td>
                        <td>
                          7/31/2013
                        </td>
                      </tr>
                      <tr class="altItem">
                        <td align="center">
                          <a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$Control1$gv','Select$3')">
                                                        Edit</a>
                        </td>
                        <td align="center" style="width: 15px;">
                        </td>
                        <td>
                          Test3</td>
                        <td>
                          &nbsp;
                        </td>
                        <td>
                          &nbsp;
                        </td>
                        <td>
                          &nbsp;
                        </td>
                        <td>
                          &nbsp;
                        </td>
                        <td>
                          8/23/2011
                        </td>
                      </tr>
                      <tr class="item">
                        <td align="center">
                          <a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$Control1$gv','Select$4')">
                                                        Edit</a>
                        </td>
                        <td align="center" style="width: 15px;">
                        </td>
                        <td>
                          Test4</td>
                        <td>
                          2
                        </td>
                        <td>
                          Employer
                        </td>
                        <td>
                          &nbsp;
                        </td>
                        <td>
                          &nbsp;
                        </td>
                        <td>
                          7/31/2012
                        </td>
                      </tr>
                      <tr class="altItem">
                        <td align="center">
                          <a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$Control1$gv','Select$5')">
                                                        Edit</a>
                        </td>
                        <td align="center" style="width: 15px;">
                        </td>
                        <td>
                          Test5</td>
                        <td>
                          3
                        </td>
                        <td>
                          Employer&nbsp;
                        </td>
                        <td>
                          &nbsp;
                        </td>
                        <td>
                          &nbsp;
                        </td>
                        <td>
                          7/31/2012
                        </td>
                      </tr>
                      <tr class="item">
                        <td align="center">
                          <a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$Control1$gv','Select$6')">
                                                        Edit</a>
                        </td>
                        <td align="center" style="width: 15px;">
                        </td>
                        <td>
                          Test6
                        </td>
                        <td>
                          a
                        </td>
                        <td>
                          &nbsp;
                        </td>
                        <td>
                          &nbsp;
                        </td>
                        <td>
                          &nbsp;
                        </td>
                        <td>
                          7/20/2012
                        </td>
                      </tr>
                    </table>
                  </div>
                </div>
              </div>
            </div>
          </td>
        </tr>
        <tr class="footer">
          <td>
          </td>
        </tr>
      </table>
    </form>
  </body>

</html>

私が得ている結果はすべての一致する要素ですが、どうすればtdだけを取得できtestますか?

<td >
test
</td>
<td >
DEMO TEST OCT 25
</td>
<td class="firefinder-match">
DEMO TEST OCT 25
</td>
<td >
DEMO TEST OCT 25
</td>
<td >
DEMO TEST OCT 25
</td>

<td >
DEMO TEST OCT 25
</td>
4

2 に答える 2

0

問題はにありますtr.item。そのクラスには複数の行があり、それらすべてを選択しています。疑似クラスを使用してより具体的にし、すべてではなくfirst-child最初のクラスのみを選択するようにします。tr.item

于 2012-12-11T22:19:23.777 に答える
0

取得方法は次のとおりです。

table#ctl00_ContentPlaceHolder1_Control1_gv.gv tbody tr.item:nth-child(3) > td:nth-of-type(3)
于 2012-12-11T22:35:46.067 に答える