scrapertools.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:pelisalacarta-ce 作者: pelisalacarta-ce 项目源码 文件源码
def decodeHtmlentities(string):
    string = entitiesfix(string)
    entity_re = re.compile("&(#?)(\d{1,5}|\w{1,8});")

    def substitute_entity(match):
        from htmlentitydefs import name2codepoint as n2cp
        ent = match.group(2)
        if match.group(1) == "#":
            return unichr(int(ent)).encode('utf-8')
        else:
            cp = n2cp.get(ent)

            if cp:
                return unichr(cp).encode('utf-8')
            else:
                return match.group()

    return entity_re.subn(substitute_entity, string)[0]
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号