How to find all comments with Beautiful Soup
This question was asked four years ago, but the answer is now out of date for BS4. I want to delete all comments in my html file using beautiful soup. Since BS4 makes each comment as a special type of navigable string , I thought this code would work: for comments in soup.find_all('comment'): comments.decompose() So that didn't work.... How do I find all comments using BS4? Flickerlight You can pass a function to find_all() to help it check whether the string is a Comment. For example I have below html: <body> <!-- Branding and main navigation --> <div class="Branding">The Science & Safety