【发布时间】:2012-03-07 07:53:51
【问题描述】:
我在课堂上有这个方法
class CatList:
lista = codecs.open('googlecat.txt', 'r', encoding='utf-8').read()
soup = BeautifulSoup(lista)
# parse the list through BeautifulSoup
def parseList(tag):
if tag.name == 'ul':
return [parseList(item)
for item in tag.findAll('li', recursive=False)]
elif tag.name == 'li':
if tag.ul is None:
return tag.text
else:
return (tag.contents[0].string.strip(), parseList(tag.ul))
但是当我尝试这样称呼它时:
myCL = CatList()
myList = myCL.parseList(myCL.soup.ul)
我有以下错误:
parseList() takes exactly 1 argument (2 given)
我尝试将 self 作为参数添加到方法中,但是当我这样做时,我得到的错误如下:
global name 'parseList' is not defined
我不太清楚这实际上是如何工作的。
有什么提示吗?
谢谢
【问题讨论】: