Beautiful Soup and extracting a div and its contents by ID

后端 未结 13 1512
死守一世寂寞
死守一世寂寞 2020-11-30 19:54
soup.find(\"tagName\", { \"id\" : \"articlebody\" })

Why does this NOT return the

...
tags
13条回答
  •  情深已故
    2020-11-30 20:19

    In the beautifulsoup source this line allows divs to be nested within divs; so your concern in lukas' comment wouldn't be valid.

    NESTABLE_BLOCK_TAGS = ['blockquote', 'div', 'fieldset', 'ins', 'del']
    

    What I think you need to do is to specify the attrs you want such as

    source.find('div', attrs={'id':'articlebody'})
    

提交回复
热议问题