Sure, you can just select
, find
, or find_all
the div
s of interest in the usual way, and then call decompose()
on those divs.
For instance, if you want to remove all divs with class sidebar
, you could do that 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 that with
soup.find('div', id="main-content").decompose()
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…