gatheringcrow 2022-06-06 19:18 采纳率: 66.7%
浏览 38
已结题

python正则表达式bug

代码
hasNextPage=re.search('{"hasNextPage":(.*?),', text)
print(hasNextPage.group(1))
text:
{"isAudienceReview":false,"pageInfo":{"hasNextPage":true,"hasPreviousPage":true,之后省略
为什么会产生错误:AttributeError: 'NoneType' object has no attribute 'group

img

  • 写回答

2条回答 默认 最新

  • 请叫我问哥 新星创作者: python技术领域 2022-06-06 19:24
    关注

    说明没有找到啊,hasNextPage是空的
    你是不是哪里写错了,我复制下来运行是正常的:

    import re
    text = '{"isAudienceReview":false,"pageInfo":{"hasNextPage":true,"hasPreviousPage":true,'
    hasNextPage=re.search('{"hasNextPage":(.*?),', text)
    print(hasNextPage.group(1))
    

    结果

    true
    
    评论 编辑记录

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 6月7日
  • 修改了问题 6月6日
  • 创建了问题 6月6日