with open(stopwordfile, 'r') as f:
    stopwords = '|'.join(f.read().lower().split())
regex = re.compile('.*<div class="body">(.*?)</div>.*', re.DOTALL)
reg123 = re.compile('(</?[ap][^>]*>|"|\\W+|' + stopwords + ')')
totalfreq = defaultdict(int)
filewords = {}
for filename in (fn for fn in os.listdir(path) if fn[-5:] == '.html'):
    with open(path + filename, 'r') as f:
        ch = regex.findall(f.read().lower())[0]
ch = reg123.sub(' ', ch)
words = ch.strip().split()
freq = defaultdict(int)
for w in words:
    totalfreq[w] += 1
freq[w] += 1
filewords[filename] = freq
print(totalfreq)
Counting frequency of words in documents using python regex