Skip to content Skip to sidebar Skip to footer

Remove Comment Tag But Not Content With Beautifulsoup

I'm practicing some web scraping using BeautifulSoup, specifically I'm looking at NFL game data and more specifically the 'Team Stats' table on this page (https://www.pro-football-

Solution 1:

from bs4 import BeautifulSoup, Comment
for comments in soup.findAll(text=lambda text:isinstance(text, Comment)):
    comments.extract()

From this you will be able to get all the comments out and get the text in between comments and put it in the BS4 to extract data within. Hope this works.


Post a Comment for "Remove Comment Tag But Not Content With Beautifulsoup"