[英]Removing all Emojis from Text
這個問題在這里被問過Python :如何刪除所有表情符號沒有解決方案,我已經邁出了解決方案的一步。 但需要幫助完成它。
我從 emoji 網站獲取了所有 emoji 十六進制代碼點: https ://www.unicode.org/emoji/charts/emoji-ordering.txt
然后我像這樣讀入文件:
file = open('emoji-ordering.txt')
temp = file.readline()
final_list = []
while temp != '':
#print(temp)
if not temp[0] == '#' :
utf_8_values = ((temp.split(';')[0]).rstrip()).split(' ')
values = ["u\\"+(word[0]+((8 - len(word[2:]))*'0' + word[2:]).rstrip()) for word in utf_8_values]
#print(values[0])
final_list = final_list + values
temp = file.readline()
print(final_list)
我希望這會給我 unicode 文字。 它沒有,我的目標是獲取 unicode 文字,以便我可以使用最后一個問題的部分解決方案並能夠排除所有表情符號。 任何想法我們需要什么來獲得解決方案?
pip install emoji
這是一個使用表情符號庫的get_emoji_regexp()
的 Python 腳本。
它從文件中讀取文本並將無表情符號的文本寫入另一個文件。
import emoji
import re
def strip_emoji(text):
print(emoji.emoji_count(text))
new_text = re.sub(emoji.get_emoji_regexp(), r"", text)
return new_text
with open("my_file.md", "r") as file:
old_text = file.read()
no_emoji_text = strip_emoji(old_text)
with open("file.md", "w+") as new_file:
new_file.write(no_emoji_text)
安裝表情符號
pip install emoji
然后簡單地運行
emoji.replace_emoji(text)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.