class UrlFinder(HTMLParser): ''' Класс-наследник HTMLParser. ''' def __init__(self): HTMLParser.__init__(self) self.links = [] self.pagen = [] self.mail = [] def handle_starttag(self, tag, attrs): attrs = dict(attrs) # если находим тег 'a' if 'a' == tag: try: if 'mailto' in attrs['href']: self.mail.append(attrs['href']) if 'page' in attrs['href']: self.page.append(attrs['href']) # записываем значение аттрибута href в список-свойство links нашего класса self.links.append(attrs['href']) if 'profile' in attrs['href']: self.profile.append(attrs['href']) except: pass
Так вот выдает такую ошибку.
File "testmailtoteg.py", line 29 if 'page' in attrs['href']: ^ IndentationError: unindent does not match any outer indentation level
А если убрать код:
if 'page' in attrs['href']: self.mail.append(attrs['href'])