zoukankan      html  css  js  c++  java
  • pyquery CSS选择器兄弟元素

    html = '''
    <div class="wrap">
        <div id="container">
            <ul class="list">
                 <li class="item-0">first item</li>
                 <li class="item-1"><a href="link2.html">second item</a></li>
                 <li class="item-0 active"><a href="link3.html"><span class="bold">third item</span></a></li>
                 <li class="item-1 active"><a href="link4.html">fourth item</a></li>
                 <li class="item-0"><a href="link5.html">fifth item</a></li>
             </ul>
         </div>
     </div>
    '''
    from pyquery import PyQuery as pq
    doc = pq(html)
    li = doc('.list .item-0.active')
    print(li.siblings())#打印除了选中元素以外的所有兄弟元素
    '''
    <li class="item-1"><a href="link2.html">second item</a></li>
                 <li class="item-0">first item</li>
                 <li class="item-1 active"><a href="link4.html">fourth item</a></li>
                 <li class="item-0"><a href="link5.html">fifth item</a></li>
    '''
    html = '''
    <div class="wrap">
        <div id="container">
            <ul class="list">
                 <li class="item-0">first item</li>
                 <li class="item-1"><a href="link2.html">second item</a></li>
                 <li class="item-0 active"><a href="link3.html"><span class="bold">third item</span></a></li>
                 <li class="item-1 active"><a href="link4.html">fourth item</a></li>
                 <li class="item-0"><a href="link5.html">fifth item</a></li>
             </ul>
         </div>
     </div>
    '''
    from pyquery import PyQuery as pq
    doc = pq(html)
    li = doc('.list .item-0.active')
    print(li.siblings('.active'))#打印选中元素
  • 相关阅读:
    插入排序(二)
    选择排序(一)
    (转)示例化讲解RIP路由更新机制
    Css元素居中设置
    (转)盒子概念和DiV布局
    (转)浅析CSS——元素重叠及position定位的z-index顺序
    (转)Java中的static关键字解析
    (转)字符串循环移位
    linux把某个文件拷贝到不同的目录下面
    linux中查找文件并合并文件
  • 原文地址:https://www.cnblogs.com/liangliangzz/p/10273330.html
Copyright © 2011-2022 走看看