代码之家  ›  专栏  ›  技术社区  ›  Rakib

使用BeautifulSoup删除具有特定id的div时出错

  •  0
  • Rakib  · 技术社区  · 6 年前

    我正试着用一个特殊的 身份证件 使用美容品组。

    from django import template
    from bs4 import BeautifulSoup
    
    register = template.Library()
    
    @register.filter(name='reset_html_styles')
    def reset_html_styles(value):
        # value = '<div class="test"><div dir="ltr" id="divRplyFwdMsg"><p>Some paragraph</p></div></div>'
        soup = BeautifulSoup(value, 'html5lib')
        soup.find('div', id='divRplyFwdMsg').decompose()
        return str(soup)
    

    Error: 'NoneType' object has no attribute 'decompose'
    


    我在用 python 3.6.5 , django 2.0 beautifulsoup4 4.6.0

    0 回复  |  直到 6 年前