您当前的位置: 首页 > 

OperationalError: (1366, "Incorrect string value)

彭世瑜 发布时间:2018-07-09 14:41:18 ,浏览量:4

python2爬虫抓取数据的时候,保存到数据库报错:

OperationalError: (1366, "Incorrect string value)

发现字符中存在表情符号 使用re正则库将表情符号过滤掉即可, 去除字符串中emoji符号

# 过滤表情符号
    def filter(self, text):
        try:
            text = unicode(text, "utf-8")
        except TypeError as e:
            pass

        try:
            highpoints = re.compile(u'[\U00010000-\U0010ffff]')
        except re.error:
            highpoints = re.compile(u'[\uD800-\uDBFF][\uDC00-\uDFFF]')

        return highpoints.sub(u'', text)

参考: python2 去除 字符串中emoji 符号,去除所有4字节utf8字符

关注
打赏
1688896170
查看更多评论

彭世瑜

暂无认证

  • 4浏览

    0关注

    2727博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文
立即登录/注册

微信扫码登录

0.2385s