Answer the question
In order to leave comments, you need to log in
There is a script for generating meta keywords, need to expand the conditions: strip_tags in "from django.utils.html import strip_tags"?
There is a script for generating meta keywords, you need to expand the conditions: strip_tags django.utils.html strip_tags. Disable - strip_tags - capture keywords in: "a href=" ... ", script ... /script" etc etc...
import re
import collections
from io import StringIO
from django.utils.html import strip_tags
# Подсчитывает слова в файлах шаблонов и вставляет ключевые слова на страницу
WORD_COUNT_MIN = 2
WORD_LENGTH_MIN = 4
# Необязательный список слов, которые вы можете не использовать в качестве мета-тегов.
nogo_list = (
[]
# ['event', 'current', 'function', 'parent']
)
# meta_keywords ( html строка ) =>
# # возвращает список ключевых слов, отличных от html, в виде строки, разделенной запятыми,
# для слов, соответствующих квалификации, выбранной выше.
def meta_keywords(str_file):
key_object = collections.Counter()
strio_object = StringIO(str_file)
for line in strio_object.readlines():
key_object.update(re.findall(r"[\w]+", strip_tags(line).lower()))
wordlist = []
for word, count in key_object.most_common():
if (
len(word) > (WORD_LENGTH_MIN - 2)
and count > (WORD_COUNT_MIN - 4)
and word not in nogo_list
):
wordlist.append(word)
return ', '.join(wordlist)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question