Skip to main content
The Cloistered Monkey
  • Pages
  • Archive
  • Tags
  • RSS feed
  • Projects
    Ape Iron Beach Pig Rump & Thigh Bowling For Data Give the Fish Neurotic Networking Terribilis Ludum Visions, Voices, Data
  • Source

Smoothing Out a Beautiful Soup Tree

Cloistered Monkey

2020-08-05 16:58

Source

If you edit the HTML tree in Beautiful Soup you should call the smooth method to smooth out any funkiness that got introduced.

from bs4 import BeautifulSoup
soup = BeautifulSoup(html)

for tag_id in tag_ids_to_destroy:
    tag = soup.find(id=tag_id)
    tag.decompose()

soup.smooth()
  • beautiful soup
  • html
  • slipnote
  • web-scraping
  • Previous post
  • Next post
Scribbled by the Cloistered Monkey - Powered by Nikola
This work is licensed under CC BY 4.0