diff --git a/src/calibre/ebooks/mobi/reader.py b/src/calibre/ebooks/mobi/reader.py index fa1c0fc0d8..44d3fbd9f7 100644 --- a/src/calibre/ebooks/mobi/reader.py +++ b/src/calibre/ebooks/mobi/reader.py @@ -296,6 +296,14 @@ class MobiReader(object): from lxml.html import soupparser print 'Markup contains unclosed
tags, parsing using BeatifulSoup' root = soupparser.fromstring(self.processed_html) + if root[0].tag != 'html': + nroot = html.fromstring('
') + bod = nroot.find('body') + for child in list(root): + child.getparent().remove(child) + bod.append(child) + root = nroot + self.upshift_markup(root) guides = root.xpath('//guide') guide = guides[0] if guides else None