[Untitled] Python crawler: AttributeError: ‘tuple’ object has no attribute ‘append’

Project scenario:

Add element to list


Problem Description

An error occurred: AttributeError: ‘tuple’ object has no attribute ‘append’

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

Cause Analysis:

tuples cannot be added, indicating that TEXT is a tuple type.
Looking forward, I found that I made a mistake when setting the TEXT blank list. It should be written as TEXT = []


solution:

TEXT = () changed to TEXT = []

おすすめ

転載: blog.csdn.net/qq_52671517/article/details/124523523