【无标题】Python爬虫:AttributeError: ‘tuple’ object has no attribute ‘append’

项目场景:

向列表中添加元素


问题描述

出现错误:AttributeError: ‘tuple’ object has no attribute ‘append’

 TEXT = ()
 #表头
 for th in table.select('th'):
     header = th.text
     TEXT.append(header)
 print(TEXT)

原因分析:

元组不可添加,说明TEXT是元组类型。
往前找发现设置TEXT空白列表时写错了,应该写成TEXT = []


解决方案:

TEXT = ()修改为TEXT = []

猜你喜欢

转载自blog.csdn.net/qq_52671517/article/details/124523523
今日推荐