1👍
✅
You need to remove all the HTML Tags from blog.content and then count no of words. You can do this in two ways:
- Extract text from HTML / blog.content using BeautifulSoup.
from bs4 import BeautifulSoup soup = BeautifulSoup(blog.content, 'html.parser') word_count = len(soup.get_text().split())
OR
- Use regex for removing all the HTML Tags and then take word count.
import re text = re.sub(r"]*>", " ", blog.content) word_count = len(text.split())
Source:stackexchange.com