From f776aa6753a2bd367287c668006e91b5add02b32 Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Fri, 16 Sep 2011 09:26:36 +0200 Subject: [PATCH] footnotes fix --- librarian/html.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/librarian/html.py b/librarian/html.py index 1c141f3..9869513 100644 --- a/librarian/html.py +++ b/librarian/html.py @@ -268,10 +268,12 @@ def extract_annotations(html_path): """For each annotation, yields a tuple: anchor, text, html.""" parser = etree.HTMLParser(encoding='utf-8') tree = etree.parse(html_path, parser) - for footnote in tree.find('//*[@id="footnotes"]').findall('div'): - anchor = footnote.find('a[@href]').get('href') - del footnote[:2] - text_str = etree.tostring(footnote, method='text', encoding='utf-8') - html_str = etree.tostring(footnote, method='html', encoding='utf-8') - yield anchor, text_str, html_str + footnotes = tree.find('//*[@id="footnotes"]') + if footnotes is not None: + for footnote in footnotes.findall('div'): + anchor = footnote.find('a[@href]').get('href') + del footnote[:2] + text_str = etree.tostring(footnote, method='text', encoding='utf-8').strip() + html_str = etree.tostring(footnote, method='html', encoding='utf-8') + yield anchor, text_str, html_str -- 2.20.1