'Convenience method that takes an URL to the index page and returns
a `BeautifulSoup <https://www.crummy.com/software/BeautifulSoup/bs3/documentation.html>`_
of it.
`url_or_raw`: Either a URL or the downloaded index page as a string'

def index_to_soup(self, url_or_raw, raw=False, as_tree=False):

    if re.match('\\w+://', url_or_raw):
        br = self.clone_browser(self.browser)
        open_func = getattr(br, 'open_novisit', br.open)
        with closing(open_func(url_or_raw)) as f:
            _raw = f.read()
        if (not _raw):
            raise RuntimeError(('Could    not    fetch    index    from    %s' % url_or_raw))
    else:
        _raw = url_or_raw
    if raw:
        return _raw
    if ((not isinstance(_raw, unicode)) and self.encoding):
        if callable(self.encoding):
            _raw = self.encoding(_raw)
        else:
            _raw = _raw.decode(self.encoding, 'replace')
    from calibre.ebooks.chardet import strip_encoding_declarations, xml_to_unicode
    from calibre.utils.cleantext import clean_xml_chars
    if isinstance(_raw, unicode):
        _raw = strip_encoding_declarations(_raw)
    else:
        _raw = xml_to_unicode(_raw, strip_encoding_pats=True, resolve_entities=True)[0]
    _raw = clean_xml_chars(_raw)
    if as_tree:
        from html5_parser import parse
        return parse(_raw)
    else:
        from html5_parser.soup import set_soup_module, parse
        set_soup_module(sys.modules[BeautifulSoup.__module__])
        return parse(_raw, return_root=False)
