python处理emoji表情

python处理emoji表情

 

爬到有表情的内容存mysql会报错,mongodb则没有事,解决办法 去除表情后存储。

pypi有现成的库emoji来处理emoji字符串  : https://pypi.org/project/emoji/

 

安装:

pip install emoji --upgrade

eg:

复制代码
>> import emoji
>> print(emoji.emojize('Python is :thumbs_up:'))
Python is 👍
>> print(emoji.emojize('Python is :thumbsup:', use_aliases=True))
Python is 👍
>> print(emoji.demojize('Python is 👍'))
Python is :thumbs_up:
复制代码

 

替换函数

复制代码
def filter_emoji(desstr,restr=''):
    #过滤表情
    try:
        co = re.compile(u'[\U00010000-\U0010ffff]')
    except re.error:
        co = re.compile(u'[\uD800-\uDBFF][\uDC00-\uDFFF]')
    return co.sub(restr, desstr)
复制代码

 

 
 
0
0
 
 
 
« 上一篇: multipart/form-data请求 -Python 两种解决办法
» 下一篇: chromedriver与chrome最新版本对应表 转自-河岸上的酸菜鱼 简书地址-https://www.jianshu.com/u/bbea92f78aca
posted @ 2020-03-20 19:04  wzqwer  阅读(684)  评论(0编辑  收藏
posted @ 2020-09-16 16:53  逐梦~前行  阅读(1583)  评论(0编辑  收藏  举报