Beautiful Soup and extracting a div and its contents by ID

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

Why does this NOT return the

...
tags
相关标签:
13条回答
  • 2020-11-30 20:36

    You should post your example document, because the code works fine:

    >>> import BeautifulSoup
    >>> soup = BeautifulSoup.BeautifulSoup('<html><body><div id="articlebody"> ... </div></body></html')
    >>> soup.find("div", {"id": "articlebody"})
    <div id="articlebody"> ... </div>
    

    Finding <div>s inside <div>s works as well:

    >>> soup = BeautifulSoup.BeautifulSoup('<html><body><div><div id="articlebody"> ... </div></div></body></html')
    >>> soup.find("div", {"id": "articlebody"})
    <div id="articlebody"> ... </div>
    
    0 讨论(0)
提交回复
热议问题