美文网首页
re.sub()函数

re.sub()函数

作者: 认真点啊 | 来源:发表于2018-07-18 17:26 被阅读0次

    在使用re.sub()函数进行过滤时,注意第三个参数值是字符类型,不能是byte类型,否则会出现以下错误:

    TypeError: expected string or bytes-like object
    

    可使用str()进行转换

     'name': re.sub('[\t\n\r]','',str(item.find('.p-name').text())),
     'shop': re.sub('[\t\n\r]','',str(item.find('.p-shop .curr-shop').attr('title')))
    

    相关文章

      网友评论

          本文标题:re.sub()函数

          本文链接:https://www.haomeiwen.com/subject/rwcapftx.html