python爬虫报错{AttributeError: 'NoneType' object has no attribute 'group'}

python报错
爬虫初学者,代码运行过程出现如下错误,想问一下大拿们是不是正则表达式有问题,是的话应该怎么改呢?如果不是,还可能是有些别的什么原因导致错误呢?
{AttributeError: 'NoneType' object has no attribute 'group'}

img

img

是的,看你这个报错就是 re.search() 方法没有匹配到,返回的结果是None,而后面紧接着就调用了 group(1) 方法,所以才报了这个错

74行改成:试下

matchresult=re.search(change_page_pattern_compile,
                                         second_get_res.text)
if not matchresult:
    print("error")  
else:
    print(matchresult.group(1))