码迷,mamicode.com
首页 > 其他好文 > 详细

遍历单个元素

时间:2019-01-15 18:28:35      阅读:170      评论:0      收藏:0      [点我收藏+]

标签:href   fir   imp   sha   link   csharp   html   active   sharp   

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)

  

遍历单个元素

标签:href   fir   imp   sha   link   csharp   html   active   sharp   

原文地址:https://www.cnblogs.com/liangliangzz/p/10273366.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!