Есть несколько способов сделать это. Я бы порекомендовал создать функцию «очистки текста»
def cleanText(text):
new_text = ""
for c in text: # for each character in the text
if c.isalnum(): # check if it is either a letter or number (alphanumeric)
new_text += c
return new_text
или если вы хотите включить определенные не алфавитно-цифровые числа
def cleanText(text):
valid_symbols = "!@#$%^&*()" # <-- add whatever symbols you want here
new_text = ""
for c in text: # for each character in the text
if c.isalnum() or c in valid_symbols: # check if alphanumeric or a valid symbol
new_text += c
return new_text
, чтобы в вашем скрипте вы могли что-то сделатькак
commentBody = cleanText(top_comment.body)