getitem的重要性:使用Python解析HTML

2024-10-03 04:32:45 发布

您现在位置:Python中文网/ 问答频道 /正文

class mainprogram():
 def getData(self, file, begin, end):
    parser = MyHTMLParser()
    f = open(file);
    rawcontent = f.read()

    #Get main content
    content = rawcontent.split('<div id="header"')[1];
    content = content.split('</html>')[0];

    del parsed_data[:]
    html = content.split(begin)[1];
    html = html.split(end)[0];
    parser.feed(html);
    result = list(parsed_data);
    return result;

我正处于练习Python的阶段,当我在做一个与Python相关的作业时,我被卡住了。上面的代码片段使用htmlparser解析.msg文件,将其转换为csv格式。 有谁能解释一下[1][0]在下面这几行中意味着什么

content = rawcontent.split('<div id="header"')[1];
content = content.split('</html>')[0];

目前我正在使用Python社区版本进行开发,当我突出显示特定的[1]或[0]时,它显示为

class list

def __getitem__(self, y)

Tags: selfdividparserdefhtmlcontentparsed