Python RuntimeError:解析HTML时超过最大递归深度

Python RuntimeError:解析HTML时超过最大递归深度,python,html,parsing,Python,Html,Parsing,我有一个测试程序,试图从每个HTML标记中提取所有文本。在我重写\uuuu init\uuu函数之前,它似乎一直在工作 我得到一个错误: File "./html.py", line 9, in __init__ TransParser.__init__(self) File "./html.py", line 9, in __init__ TransParser.__init__(self) File "./html.py", line 9, in __init__

我有一个测试程序,试图从每个HTML标记中提取所有文本。在我重写
\uuuu init\uuu
函数之前,它似乎一直在工作

我得到一个错误:

 File "./html.py", line 9, in __init__
    TransParser.__init__(self)
  File "./html.py", line 9, in __init__
    TransParser.__init__(self)
  File "./html.py", line 9, in __init__
    TransParser.__init__(self)
  File "./html.py", line 9, in __init__
    TransParser.__init__(self)
RuntimeError: maximum recursion depth exceeded
节目如下:

from HTMLParser import HTMLParser

trans = {
'History': 'History TRANSLATED',
'Acknowledgements': 'Acknowledgements TRANSLATED'
}

inputHTML = """<table border="0" cellspacing="0" cellpadding="0">
    <tbody>
      <tr>
        <td class="section-title"><a href="/about%20/history">History</a>        </td>

        <td class="section-title"><a href="/about/team">Project Team</a></td>

        <td class="section-title"><a href="/about/data">Contributors of data</a></td>

        <td class="section-title"><a href=
        "/about/acknowledgements">Acknowledgements</a></td>

        <td class="section-title"><a href="/about/origins">African Origins
        Project</a></td>

        <td class="section-title"><a href="/about/contacts">Contact us</a></td>
      </tr>
    </tbody>
  </table>

  <table border="0" cellspacing="0" cellpadding="0">
    <tbody>
      <tr>
        <td class="section-desc">A brief account of the origins of a single multi-source
        dataset of the trans-Atlantic slave trade and its realization first as a CD-ROM
        published by Cambridge University Press in 1999 and now, in an expanded version,
        on the Voyages website.</td>

        <td class="section-desc">Names of the principal investigators, of members of the
        project development team, and of individuals serving on the steering committee
        and advisory board.</td>

        <td class="section-desc">Names of scholars and researchers whose findings on the
       trans-Atlantic slave trade have been incorporated into the Voyages Database.</td>

        <td class="section-desc">Major sponsors and institutional partners of the Voyages
        website, as well as other organizations and individuals who have assisted the
        work of the project team.</td>

        <td class="section-desc">A scholar-public collaborative project using audio
        recordings of names in African Names Database to trace the geographic origins of
         Africans transported in the transatlantic slave trade.</td>

        <td class="section-desc">Members of the Voyages editorial board and the email
         address for contacting the website.</td>
      </tr>
     </tbody>
  </table>"""


class TransParser(HTMLParser):
    def __init__(self):
        TransParser.__init__(self)
        self.trans_data = self.rawdata

    def handle_data(self, data):
         data = data.strip()
        if data:
            section = trans.get(data, data)
            #self.trans_data = self.trans_data.replace(data, section)

parser = TransParser()
parser.feed(inputHTML)
从HTMLParser导入HTMLParser
trans={
‘历史’:‘历史翻译’,
“确认”:“已翻译确认”
}
INPUTTML=“”
简单介绍单一多源的起源
跨大西洋奴隶贸易数据集及其首次作为光盘实现
由剑桥大学出版社于1999年出版,现为扩充版,
在航海网站上。
主要调查人员、调查组成员的姓名
项目开发团队和指导委员会成员
和咨询委员会。
研究人员和学者的姓名,他们在
跨大西洋贩卖奴隶已被纳入航海数据库。
航行的主要赞助者和机构合作伙伴
网站,以及协助
项目组的工作。
使用音频的学者公共协作项目
非洲地名数据库中的地名记录,以追踪非洲地名的地理起源
非洲人在跨大西洋奴隶贸易中被运送。
航海杂志编辑委员会成员和电子邮件
联系网站的地址。
"""
类TransParser(HTMLPasser):
定义初始化(自):
TransParser.\uuuuu init\uuuuuuu(自)
self.trans_data=self.rawdata
def句柄_数据(自身、数据):
data=data.strip()
如果数据:
section=trans.get(数据,数据)
#self.trans_data=self.trans_data.replace(数据,部分)
parser=TransParser()
提要(inputtml)
修复

class TransParser(HTMLParser):
    def __init__(self):
        HTMLParser.__init__(self)
        ..
        ..
修复

class TransParser(HTMLParser):
    def __init__(self):
        HTMLParser.__init__(self)
        ..
        ..
你想在这里干什么?init方法调用自身;这是无限递归。您的意思是调用父级的init方法吗?那就是

        super().__init__(self)
你想在这里干什么?init方法调用自身;这是无限递归。您的意思是调用父级的init方法吗?那就是

        super().__init__(self)