href = i.attrs['href']
lst.append(re.findall(r"[s][hz]\d{6}", href)[0])
#IndexError: list index out of range
修改为:
try:
href = i.attrs['href']
lst.append(re.findall(r"[s][hz]\d{6}", href)[0])
except:
continue
解决方法:加上try…except 错误机制跳过tr空值