Of course, you can just select , find or find_all the div interest in the usual way, and then call decompose() on those divs.
For example, if you want to remove all sidebar with the sidebar class, you can do this with
# replace with `soup.findAll` if you are using BeautifulSoup3 for div in soup.find_all("div", {'class':'sidebar'}): div.decompose()
If you want to remove a div with a specific id , say main-content , you can do this with
soup.find('div', id="main-content").decompose()
lemonhead
source share