# Buggy code
def parse(self, data, mode):
    """
    Parse search results for items.

    :param data: The raw response from a search
    :param mode: The current mode used to search, e.g. RSS

    :return: A list of items found
    """
    items = []

    with BS4Parser(data, "html5lib") as html:
        torrent_table = html("table", class_="table2")

        if mode != "RSS" and torrent_table and len(torrent_table) < 2:
            logger.log(
                "Data returned from provider does not contain any {0}torrents".format(
                    "confirmed " if self.confirmed else ""
                ),
                logger.DEBUG,
            )
            return items

        torrent_table = torrent_table[0 if mode == "RSS" else 1]
        torrent_rows = torrent_table("tr")

        # Skip the first row, since it isn't a valid result
        for row in torrent_rows[1:]:
            cells = row("td")
            try:
                verified = row("img", title="Verified torrent")
                if self.confirmed and not verified:
                    continue

                url = row.find("a", rel="nofollow")
                title_info = row("a")
                info = title_info[1]["href"]
                if not all([url, title_info, info]):
                    continue

                title = title_info[1].get_text(strip=True)
                title2 = id_regex.search(info).group(1)
                if len(title) < len(title2):
                    title = title2.replace("-", " ")
                torrent_id = id_regex.search(info).group(2)
                torrent_hash = hash_regex.search(url["href"]).group(2)
                if not all([title, torrent_id, torrent_hash]):
                    continue

                with suppress(requests.exceptions.Timeout):
                    # Suppress the timeout since we are not interested in actually getting the results
                    self.session.get(
                        self.urls["update"],
                        timeout=0.1,
                        params={"torrent_id": torrent_id, "infohash": torrent_hash},
                    )

                # Remove comma as thousands separator from larger number like 2,000 seeders = 2000
                seeders = try_int(cells[3].get_text(strip=True).replace(",", ""))
                leechers = try_int(cells[4].get_text(strip=True).replace(",", ""))
                size = convert_size(cells[2].get_text(strip=True)) or -1
                download_url = "magnet:?xt=urn:btih:{hash}&dn={title}{trackers}".format(
                    hash=torrent_hash, title=title, trackers=self._custom_trackers
                )

                if seeders < min(self.minseed, 1):
                    if mode != "RSS":
                        logger.log(
                            "Discarding torrent because it doesn't meet the "
                            "minimum seeders: {0}. Seeders: {1}".format(title, seeders),
                            logger.DEBUG,
                        )
                    continue

                item = {
                    "title": title,
                    "link": download_url,
                    "size": size,
                    "seeders": seeders,
                    "leechers": leechers,
                    "pubdate": None,
                    "torrent_hash": torrent_hash,
                }
                if mode != "RSS":
                    logger.log(
                        "Found result: {0} with {1} seeders and {2} leechers".format(
                            title, seeders, leechers
                        ),
                        logger.DEBUG,
                    )

                items.append(item)
            except (AttributeError, TypeError, KeyError, ValueError, IndexError):
                logger.log(
                    "Failed parsing provider. Traceback: {0!r}".format(
                        traceback.format_exc()
                    ),
                    logger.ERROR,
                )

    return items


# Traceback (IndexError)
2016-11-26 00:56:40 DEBUG    SEARCHQUEUE-BACKLOG-279271 :: [DOGnzb] :: [617ad17] Creating UNIQUE URL index for dognzb
2016-11-26 00:56:42 DEBUG    SEARCHQUEUE-BACKLOG-279271 :: [DOGnzb] :: [617ad17] GET URL: https://api.dognzb.cr/api?apikey=**********&t=caps [Status: 200]
2016-11-26 00:56:44 DEBUG    SEARCHQUEUE-BACKLOG-279271 :: [DOGnzb] :: [617ad17] Search mode: Episode
2016-11-26 00:56:44 DEBUG    SEARCHQUEUE-BACKLOG-279271 :: [DOGnzb] :: [617ad17] Search show using search string: indexer_id: {u'tvdbid': 279271}
2016-11-26 00:56:45 DEBUG    SEARCHQUEUE-BACKLOG-279271 :: [DOGnzb] :: [617ad17] GET URL: https://api.dognzb.cr/api?apikey=**********&tvdbid=279271&season=2&maxage=3000&cat=5000%2C5020%2C5030%2C5040%2C5045%2C5050%2C5060%2C5080&limit=100&t=tvsearch&offset=0&ep=10 [Status: 200]
2016-11-26 00:56:45 DEBUG    SEARCHQUEUE-BACKLOG-279271 :: [DOGnzb] :: [617ad17] Search mode: Episode
2016-11-26 00:56:45 DEBUG    SEARCHQUEUE-BACKLOG-279271 :: [DOGnzb] :: [617ad17] Search show using search string: Cordon S02E10
2016-11-26 00:56:45 DEBUG    SEARCHQUEUE-BACKLOG-279271 :: [DOGnzb] :: [617ad17] GET URL: https://api.dognzb.cr/api?apikey=**********&maxage=3000&cat=5000%2C5020%2C5030%2C5040%2C5045%2C5050%2C5060%2C5080&q=Cordon+S02E10&limit=100&t=search&offset=0 [Status: 200]
2016-11-26 00:56:45 INFO     SEARCHQUEUE-BACKLOG-279271 :: [Pretome] :: [617ad17] Performing episode search for Cordon
2016-11-26 00:56:45 DEBUG    SEARCHQUEUE-BACKLOG-279271 :: [Pretome] :: [617ad17] Creating UNIQUE URL index for pretome
2016-11-26 00:56:46 DEBUG    SEARCHQUEUE-BACKLOG-279271 :: [Pretome] :: [617ad17] POST URL: https://pretome.info/takelogin.php [Status: 302]
2016-11-26 00:56:46 DEBUG    SEARCHQUEUE-BACKLOG-279271 :: [Pretome] :: [617ad17] With post data: username=**********&password=**********&login_pin=**********
2016-11-26 00:56:47 DEBUG    SEARCHQUEUE-BACKLOG-279271 :: [Pretome] :: [617ad17] GET URL: https://pretome.info/index.php [Status: 200]
2016-11-26 00:56:47 DEBUG    SEARCHQUEUE-BACKLOG-279271 :: [Pretome] :: [617ad17] Search mode: Episode
2016-11-26 00:56:47 DEBUG    SEARCHQUEUE-BACKLOG-279271 :: [Pretome] :: [617ad17] Search string: Cordon S02E10
2016-11-26 00:56:48 DEBUG    SEARCHQUEUE-BACKLOG-279271 :: [Pretome] :: [617ad17] GET URL: https://pretome.info/browse.php?search=Cordon+S02E10&cat%5B%5D=7&st=1 [Status: 200]
2016-11-26 00:56:49 DEBUG    SEARCHQUEUE-BACKLOG-279271 :: [Pretome] :: [617ad17] Data returned from provider does not contain any torrents
2016-11-26 00:56:49 INFO     SEARCHQUEUE-BACKLOG-279271 :: [T411] :: [617ad17] Performing episode search for Cordon
2016-11-26 00:56:49 DEBUG    SEARCHQUEUE-BACKLOG-279271 :: [T411] :: [617ad17] Creating UNIQUE URL index for t411
2016-11-26 00:56:49 DEBUG    SEARCHQUEUE-BACKLOG-279271 :: [T411] :: [617ad17] POST URL: https://api.t411.li/auth [Status: 200]
2016-11-26 00:56:49 DEBUG    SEARCHQUEUE-BACKLOG-279271 :: [T411] :: [617ad17] With post data: username=**********&password=**********
2016-11-26 00:56:49 DEBUG    SEARCHQUEUE-BACKLOG-279271 :: [T411] :: [617ad17] Search mode: Episode
2016-11-26 00:56:49 DEBUG    SEARCHQUEUE-BACKLOG-279271 :: [T411] :: [617ad17] Search string: Cordon S02E10
2016-11-26 00:56:49 DEBUG    SEARCHQUEUE-BACKLOG-279271 :: [T411] :: [617ad17] GET URL: https://api.t411.li/torrents/search/Cordon%20S02E10*?cid=433&limit=100 [Status: 200]
2016-11-26 00:56:49 DEBUG    SEARCHQUEUE-BACKLOG-279271 :: [T411] :: [617ad17] Data returned from provider does not contain any torrents
2016-11-26 00:56:50 DEBUG    SEARCHQUEUE-BACKLOG-279271 :: [T411] :: [617ad17] GET URL: https://api.t411.li/torrents/search/Cordon%20S02E10*?cid=637&limit=100 [Status: 200]
2016-11-26 00:56:50 DEBUG    SEARCHQUEUE-BACKLOG-279271 :: [T411] :: [617ad17] Data returned from provider does not contain any torrents
2016-11-26 00:56:50 DEBUG    SEARCHQUEUE-BACKLOG-279271 :: [T411] :: [617ad17] GET URL: https://api.t411.li/torrents/search/Cordon%20S02E10*?cid=455&limit=100 [Status: 200]
2016-11-26 00:56:50 DEBUG    SEARCHQUEUE-BACKLOG-279271 :: [T411] :: [617ad17] Data returned from provider does not contain any torrents
2016-11-26 00:56:50 DEBUG    SEARCHQUEUE-BACKLOG-279271 :: [T411] :: [617ad17] GET URL: https://api.t411.li/torrents/search/Cordon%20S02E10*?cid=639&limit=100 [Status: 200]
2016-11-26 00:56:50 DEBUG    SEARCHQUEUE-BACKLOG-279271 :: [T411] :: [617ad17] Data returned from provider does not contain any torrents
2016-11-26 00:56:50 DEBUG    SEARCHQUEUE-BACKLOG-279271 :: [T411] :: [617ad17] Fallback season pack search initiate
2016-11-26 00:56:50 INFO     SEARCHQUEUE-BACKLOG-279271 :: [T411] :: [617ad17] Performing season pack search for Cordon
2016-11-26 00:56:50 INFO     SEARCHQUEUE-BACKLOG-279271 :: [TransmitTheNet] :: [617ad17] Performing episode search for Cordon
2016-11-26 00:56:50 DEBUG    SEARCHQUEUE-BACKLOG-279271 :: [TransmitTheNet] :: [617ad17] Creating UNIQUE URL index for transmitthenet
2016-11-26 00:56:51 DEBUG    SEARCHQUEUE-BACKLOG-279271 :: [TransmitTheNet] :: [617ad17] POST URL: https://transmithe.net/login.php [Status: 302]
2016-11-26 00:56:51 DEBUG    SEARCHQUEUE-BACKLOG-279271 :: [TransmitTheNet] :: [617ad17] With post data: username=**********&login=Login&password=**********&keeplogged=on
2016-11-26 00:56:51 DEBUG    SEARCHQUEUE-BACKLOG-279271 :: [TransmitTheNet] :: [617ad17] GET URL: https://transmithe.net/index.php [Status: 200]
2016-11-26 00:56:51 DEBUG    SEARCHQUEUE-BACKLOG-279271 :: [TransmitTheNet] :: [617ad17] Search mode: Episode
2016-11-26 00:56:51 DEBUG    SEARCHQUEUE-BACKLOG-279271 :: [TransmitTheNet] :: [617ad17] Search string: Cordon S02E10
2016-11-26 00:56:51 DEBUG    SEARCHQUEUE-BACKLOG-279271 :: [TransmitTheNet] :: [617ad17] GET URL: https://transmithe.net/torrents.php?filter_freeleech=0&searchtext=Cordon+S02E10&order_by=seeders&order_way=desc [Status: 200]
2016-11-26 00:56:53 DEBUG    SEARCHQUEUE-BACKLOG-279271 :: [TransmitTheNet] :: [617ad17] Data returned from provider does not contain any torrents
2016-11-26 00:56:53 INFO     SEARCHQUEUE-BACKLOG-279271 :: [Usenet-Crawler] :: [617ad17] Performing episode search for Cordon
2016-11-26 00:56:53 DEBUG    SEARCHQUEUE-BACKLOG-279271 :: [Usenet-Crawler] :: [617ad17] Creating UNIQUE URL index for usenet_crawler
2016-11-26 00:56:53 DEBUG    SEARCHQUEUE-BACKLOG-279271 :: [Usenet-Crawler] :: [617ad17] GET URL: https://www.usenet-crawler.com/api?apikey=**********&t=caps [Status: 200]
2016-11-26 00:56:56 DEBUG    SEARCHQUEUE-BACKLOG-279271 :: [Usenet-Crawler] :: [617ad17] Search mode: Episode
2016-11-26 00:56:56 DEBUG    SEARCHQUEUE-BACKLOG-279271 :: [Usenet-Crawler] :: [617ad17] Search show using search string: indexer_id: {u'tvdbid': 279271}
2016-11-26 00:56:56 DEBUG    SEARCHQUEUE-BACKLOG-279271 :: [Usenet-Crawler] :: [617ad17] GET URL: https://www.usenet-crawler.com/api?apikey=**********&tvdbid=279271&season=2&maxage=3000&cat=5000%2C5080%2C5020%2C5040%2C5050%2C5030%2C5060&limit=100&t=tvsearch&offset=0&ep=10 [Status: 200]
2016-11-26 00:56:56 DEBUG    SEARCHQUEUE-BACKLOG-279271 :: [Usenet-Crawler] :: [617ad17] Search mode: Episode
2016-11-26 00:56:56 DEBUG    SEARCHQUEUE-BACKLOG-279271 :: [Usenet-Crawler] :: [617ad17] Search show using search string: Cordon S02E10
2016-11-26 00:56:56 DEBUG    SEARCHQUEUE-BACKLOG-279271 :: [Usenet-Crawler] :: [617ad17] GET URL: https://www.usenet-crawler.com/api?apikey=**********&maxage=3000&cat=5000%2C5080%2C5020%2C5040%2C5050%2C5030%2C5060&q=Cordon+S02E10&limit=100&t=search&offset=0 [Status: 200]
2016-11-26 00:56:56 INFO     SEARCHQUEUE-BACKLOG-279271 :: [Speedcd] :: [617ad17] Performing episode search for Cordon
2016-11-26 00:56:56 DEBUG    SEARCHQUEUE-BACKLOG-279271 :: [Speedcd] :: [617ad17] Creating UNIQUE URL index for speedcd
2016-11-26 00:56:59 DEBUG    SEARCHQUEUE-BACKLOG-279271 :: [Speedcd] :: [617ad17] POST URL: https://speed.cd/takeElogin.php [Status: 302]
2016-11-26 00:56:59 DEBUG    SEARCHQUEUE-BACKLOG-279271 :: [Speedcd] :: [617ad17] With post data: username=**********&password=**********
2016-11-26 00:57:00 DEBUG    SEARCHQUEUE-BACKLOG-279271 :: [Speedcd] :: [617ad17] GET URL: https://speed.cd/ [Status: 200]
2016-11-26 00:57:00 DEBUG    SEARCHQUEUE-BACKLOG-279271 :: [Speedcd] :: [617ad17] Search mode: Episode
2016-11-26 00:57:00 DEBUG    SEARCHQUEUE-BACKLOG-279271 :: [Speedcd] :: [617ad17] Search string: Cordon S02E10
2016-11-26 00:57:05 DEBUG    SEARCHQUEUE-BACKLOG-279271 :: [Speedcd] :: [617ad17] GET URL: https://speed.cd/browse.php?c55=1&c52=1&search=Cordon+S02E10&c41=1&c50=1&c2=1&c30=1&c49=1 [Status: 200]
2016-11-26 00:57:06 DEBUG    SEARCHQUEUE-BACKLOG-279271 :: [Speedcd] :: [617ad17] Data returned from provider does not contain any torrents
2016-11-26 00:57:07 INFO     SEARCHQUEUE-BACKLOG-279271 :: [TorrentLeech] :: [617ad17] Performing episode search for Cordon
2016-11-26 00:57:07 DEBUG    SEARCHQUEUE-BACKLOG-279271 :: [TorrentLeech] :: [617ad17] Creating UNIQUE URL index for torrentleech
2016-11-26 00:57:07 DEBUG    SEARCHQUEUE-BACKLOG-279271 :: [TorrentLeech] :: [617ad17] POST URL: https://torrentleech.org/user/account/login/ [Status: 302]
2016-11-26 00:57:07 DEBUG    SEARCHQUEUE-BACKLOG-279271 :: [TorrentLeech] :: [617ad17] With post data: username=**********&remember_me=on&login=submit&password=**********
2016-11-26 00:57:07 DEBUG    SEARCHQUEUE-BACKLOG-279271 :: [TorrentLeech] :: [617ad17] GET URL: https://torrentleech.org/ [Status: 200]
2016-11-26 00:57:07 DEBUG    SEARCHQUEUE-BACKLOG-279271 :: [TorrentLeech] :: [617ad17] Search mode: Episode
2016-11-26 00:57:07 DEBUG    SEARCHQUEUE-BACKLOG-279271 :: [TorrentLeech] :: [617ad17] Search string: Cordon S02E10
2016-11-26 00:57:08 DEBUG    SEARCHQUEUE-BACKLOG-279271 :: [TorrentLeech] :: [617ad17] GET URL: https://torrentleech.org/torrents/browse?query=Cordon+S02E10&categories=2%2C7%2C35%2C26%2C32 [Status: 200]
2016-11-26 00:57:08 DEBUG    SEARCHQUEUE-BACKLOG-279271 :: [TorrentLeech] :: [617ad17] Data returned from provider does not contain any torrents
2016-11-26 00:57:08 INFO     SEARCHQUEUE-BACKLOG-279271 :: [LimeTorrents] :: [617ad17] Performing episode search for Cordon
2016-11-26 00:57:08 DEBUG    SEARCHQUEUE-BACKLOG-279271 :: [LimeTorrents] :: [617ad17] Creating UNIQUE URL index for limetorrents
2016-11-26 00:57:08 DEBUG    SEARCHQUEUE-BACKLOG-279271 :: [LimeTorrents] :: [617ad17] Search mode: Episode
2016-11-26 00:57:08 DEBUG    SEARCHQUEUE-BACKLOG-279271 :: [LimeTorrents] :: [617ad17] Search string: Cordon S02E10
2016-11-26 00:57:09 DEBUG    SEARCHQUEUE-BACKLOG-279271 :: [LimeTorrents] :: [617ad17] GET URL: https://www.limetorrents.cc/search/tv/Cordon%20S02E10/ [Status: 200]
2016-11-26 00:57:09 ERROR    SEARCHQUEUE-BACKLOG-279271 :: [LimeTorrents] :: [617ad17] Unknown exception while searching LimeTorrents. Error: 'list index out of range'
Traceback (most recent call last):
  File "/home/home/SickRage/**********/search/core.py", line 560, in searchProviders
    down_cur_quality, manual_search, manual_search_type)
  File "/home/home/SickRage/**********/providers/generic_provider.py", line 193, in find_search_results
    items_list += self.search(search_string, ep_obj=episode)
  File "/home/home/SickRage/**********/providers/torrent/html/limetorrents.py", line 98, in search
    results += self.parse(response.text, mode)
  File "/home/home/SickRage/**********/providers/torrent/html/limetorrents.py", line 121, in parse
    torrent_table = torrent_table[0 if mode == 'RSS' else 1]
IndexError: list index out of range

# Fixed code
def parse(self, data, mode):
    """
    Parse search results for items.

    :param data: The raw response from a search
    :param mode: The current mode used to search, e.g. RSS

    :return: A list of items found
    """
    items = []

    def process_column_header(th):
        return th.span.get_text() if th.span else th.get_text()

    with BS4Parser(data, "html5lib") as html:
        torrent_table = html.find("table", class_="table2")

        if not torrent_table:
            logger.log(
                "Data returned from provider does not contain any {0}torrents".format(
                    "confirmed " if self.confirmed else ""
                ),
                logger.DEBUG,
            )
            return items

        torrent_rows = torrent_table.find_all("tr")
        labels = [process_column_header(label) for label in torrent_rows[0]]

        # Skip the first row, since it isn't a valid result
        for row in torrent_rows[1:]:
            cells = row.find_all("td")

            try:
                title_cell = cells[labels.index("Torrent Name")]

                verified = title_cell.find("img", title="Verified torrent")
                if self.confirmed and not verified:
                    continue

                title_anchors = title_cell.find_all("a")
                if not title_anchors or len(title_anchors) < 2:
                    continue

                title_url = title_anchors[0].get("href")
                title = title_anchors[1].get_text(strip=True)
                regex_result = id_regex.search(title_anchors[1].get("href"))

                alt_title = regex_result.group(1)
                if len(title) < len(alt_title):
                    title = alt_title.replace("-", " ")

                torrent_id = regex_result.group(2)
                torrent_hash = hash_regex.search(title_url).group(2)
                if not all([title, torrent_id, torrent_hash]):
                    continue

                with suppress(RequestsConnectionError, Timeout):
                    # Suppress the timeout since we are not interested in actually getting the results
                    self.session.get(
                        self.urls["update"],
                        timeout=0.1,
                        params={"torrent_id": torrent_id, "infohash": torrent_hash},
                    )

                # Remove comma as thousands separator from larger number like 2,000 seeders = 2000
                seeders = try_int(
                    cells[labels.index("Seed")].get_text(strip=True).replace(",", ""), 1
                )
                leechers = try_int(
                    cells[labels.index("Leech")].get_text(strip=True).replace(",", "")
                )

                if seeders < min(self.minseed, 1):
                    if mode != "RSS":
                        logger.log(
                            "Discarding torrent because it doesn't meet the "
                            "minimum seeders: {0}. Seeders: {1}".format(title, seeders),
                            logger.DEBUG,
                        )
                    continue

                size = (
                    convert_size(cells[labels.index("Size")].get_text(strip=True)) or -1
                )
                download_url = "magnet:?xt=urn:btih:{hash}&dn={title}{trackers}".format(
                    hash=torrent_hash, title=title, trackers=self._custom_trackers
                )

                item = {
                    "title": title,
                    "link": download_url,
                    "size": size,
                    "seeders": seeders,
                    "leechers": leechers,
                    "pubdate": None,
                    "torrent_hash": torrent_hash,
                }
                if mode != "RSS":
                    logger.log(
                        "Found result: {0} with {1} seeders and {2} leechers".format(
                            title, seeders, leechers
                        ),
                        logger.DEBUG,
                    )

                items.append(item)
            except (AttributeError, TypeError, KeyError, ValueError, IndexError):
                logger.log(
                    "Failed parsing provider. Traceback: {0!r}".format(
                        traceback.format_exc()
                    ),
                    logger.ERROR,
                )

    return items