Xpath不只是获得html的父级

时间:2013-10-31 17:07:34

标签: xpath

我正在尝试仅为导航栏的父级找到xpath。我现在正在尝试的路径是`// @ [@ class ='unselectable']来自HTML的和平。

`<div class="PrimaryNavigationContainer">
                <div class="PrimaryNavigation">   
        <div class="Menu">   

        <div>    
        <a href="http://www.blah.co.uk/brands.aspx" class="unselectable"><span>
                                    Brands</span></a>
         <div class="navCol">
         <div>
             <a class="NoLink unselectable"><span>Shop by Brand</span></a>
             <div class="navCol subMenus">
              div>                  
          <a href="http://www.blah.co.uk/blah/catlist_bd4.htm" class="unselectable"><span>
                                                blah</span></a>

xpath似乎提出了顶级猫和子类别,我是因为它在两者中但不确定如何单独从chld中获取父级。感谢您提供的任何帮助

1 个答案:

答案 0 :(得分:1)

//div[@class="Menu"]/div/a[@class='unselectable']怎么样?这样您就可以避免在a div中选择subMenus