遍历单个元素
Posted 青春叛逆者
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了遍历单个元素相关的知识,希望对你有一定的参考价值。
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(‘.item-0.active‘) print(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) lis = doc(‘li‘).items()#找到所有li print(type(lis))#遍历 for li in lis: print(li)
以上是关于遍历单个元素的主要内容,如果未能解决你的问题,请参考以下文章
PHP遍历函数将单个数组转换为带有子元素的嵌套数组 - 基于父ID
817. Linked List Components - LeetCode