2015-08-21 23 views
0

它的可能性呢?得到所有的表格「tr」,除了帶有特定字符串的元素的tr。XPath - 獲取表如果子不是特定的字符串

實施例:

<div class="span5"> 
    <table class="table"> 
     <tbody> 
      <tr> 
       <th>Apple</th> 
       <td>Red</td> 
      </tr> 
      <tr> 
       <th>Banana</th> 
       <td>Yellow</td> 
      </tr> 
      <tr> 
       <th>Potato</th> 
       <td>Brown</td> 
      </tr> 
     </tbody> 
    </table> 
</div> 

簡單的例子,以2列的表,我可以選擇與下一個的Xpath表:

//div[@class='span5']/table[@class='table'] 

但其更多鈔票以選擇表沒有「TR 「其中包含:

//th[.='Potato'] 

我想通過解決這個問題來解決所有的表格和n在Python中過濾「tr」內容,但是我想用XPath過濾並優化一下我的代碼,而不會在內存中收費。

感謝

-----------------------

解決:

//div[@class='span5']/table[@class='table']//tr[./th[.!='Potato']] 
+1

'//div[@class='span5']/table[@class='table']//tr[not(th[.='''Potato'])] ' – splash58

+0

感謝splash58,你的XPath沒有工作,得到所有元素,b你幫我! 這是工作 //div[@class='span5']/table[@class='table']//tr[./th[.!=''Potato']] – Wonka

+0

至少,它的工作原理xpath測試人員,例如,那裏 - http://www.freeformatter.com/xpath-tester.html – splash58

回答

0

你的XPath可以是比如這樣簡單:

//div[@class='span5']/table[@class='table']//tr[th != 'Potato'] 
相關問題