如何在ul标签下循环li标签?

时间:2018-08-31 15:59:33

标签: python beautifulsoup

这是html

<div class="field field--name-field-rdp-fc-sf-body field--type-text-long field--label-hidden">
  <div class="field__items">
    <div class="field__item even">
      <ul>
        <li>Facilities for Interactive white board or other audio visual display </li>
        <li>Holland Blinds to external windows.</li>
      </ul>
    </div>
  </div>
</div> 
</div>

我只需要e变量中的每个li

这是我的代码

tag = soup.find('div', attrs={'class':'field--name-field-rdp-fc-sf-body'})
ultag = tag.find('ul')
for i in ultag:
    e = i.find('li')
    print(e)

1 个答案:

答案 0 :(得分:1)

这是工作代码

tag = soup.find('div', attrs={'class':'field--name-field-rdp-fc-sf-body'})
ultag = tag.find('ul')
for i in ultag.find_all('li'):
    e = i.text
    print(e)