# Buggy code
def search(self, search_strings, age=0, ep_obj=None):  # pylint: disable=too-many-locals, too-many-branches
    results = []
    if not self.login():
        return results

    # http://speed.cd/browse.php?c49=1&c50=1&c52=1&c41=1&c55=1&c2=1&c30=1&freeleech=on&search=arrow&d=on
    # Search Params
    search_params = {
        "c2": 1,  # TV/Episodes
        "c30": 1,  # Anime
        "c41": 1,  # TV/Packs
        "c49": 1,  # TV/HD
        "c50": 1,  # TV/Sports
        "c52": 1,  # TV/B-Ray
        "c55": 1,  # TV/Kids
        "search": "",
    }

    # Units
    units = ["B", "KB", "MB", "GB", "TB", "PB"]

    def process_column_header(td):
        result = ""
        if td.a and td.a.img:
            result = td.a.img.get("alt", td.a.get_text(strip=True))
        if td.img and not result:
            result = td.img.get("alt", "")
        if not result:
            result = td.get_text(strip=True)
        return result

    if self.freeleech:
        search_params["freeleech"] = "on"

    for mode in search_strings:
        items = []
        logger.log("Search Mode: {}".format(mode), logger.DEBUG)

        for search_string in search_strings[mode]:
            if mode != "RSS":
                logger.log(
                    "Search string: {}".format(search_string.decode("utf-8")),
                    logger.DEBUG,
                )

            search_params["search"] = search_string

            data = self.get_url(
                self.urls["search"], params=search_params, returns="text"
            )
            if not data:
                continue

            with BS4Parser(data, "html5lib") as html:
                torrent_table = html.find("div", class_="boxContent").find("table")
                torrent_rows = torrent_table("tr") if torrent_table else []

                # Continue only if at least one Release is found
                if len(torrent_rows) < 2:
                    logger.log(
                        "Data returned from provider does not contain any torrents",
                        logger.DEBUG,
                    )
                    continue

                labels = [
                    process_column_header(label) for label in torrent_rows[0]("th")
                ]

                # Skip column headers
                for result in torrent_rows[1:]:
                    try:
                        cells = result("td")

                        title = (
                            cells[labels.index("Title")]
                            .find("a", class_="torrent")
                            .get_text()
                        )
                        download_url = urljoin(
                            self.url,
                            cells[labels.index("Download")]
                            .find(title="Download")
                            .parent["href"],
                        )
                        if not all([title, download_url]):
                            continue

                        seeders = try_int(
                            cells[labels.index("Seeders")].get_text(strip=True)
                        )
                        leechers = try_int(
                            cells[labels.index("Leechers")].get_text(strip=True)
                        )

                        # Filter unseeded torrent
                        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

                        torrent_size = cells[labels.index("Size")].get_text()
                        torrent_size = torrent_size[:-2] + " " + torrent_size[-2:]
                        size = convert_size(torrent_size, units=units) or -1

                        item = {
                            "title": title,
                            "link": download_url,
                            "size": size,
                            "seeders": seeders,
                            "leechers": leechers,
                            "pubdate": None,
                            "hash": None,
                        }
                        if mode != "RSS":
                            logger.log(
                                "Found result: %s with %s seeders and %s leechers"
                                % (title, seeders, leechers),
                                logger.DEBUG,
                            )

                        items.append(item)
                    except StandardError:
                        continue

        # For each search mode sort all the items by seeders if available
        items.sort(key=lambda d: try_int(d.get("seeders", 0)), reverse=True)
        results += items

    return results


# Traceback (AttributeError)
SEARCHQUEUE-MANUAL-311937 :: [Speedcd] :: [3351698] Unknown exception while searching Speedcd. Error: "'NoneType' object has no attribute 'find'"
Traceback (most recent call last):
File "/home/home/SickRage/sickbeard/search.py", line 547, in searchProviders
forced_search, downCurQuality, manual_search, manual_search_type)
File "/home/home/SickRage/sickrage/providers/GenericProvider.py", line 149, in find_search_results
items_list += self.search(search_string, ep_obj=episode)
File "/home/home/SickRage/sickbeard/providers/speedcd.py", line 133, in search
torrent_table = html.find('div', class_='boxContent').find('table')
AttributeError: 'NoneType' object has no attribute 'find'

# Fixed code
def search(self, search_strings, age=0, ep_obj=None):  # pylint: disable=too-many-locals, too-many-branches
    results = []
    if not self.login():
        return results

    # http://speed.cd/browse.php?c49=1&c50=1&c52=1&c41=1&c55=1&c2=1&c30=1&freeleech=on&search=arrow&d=on
    # Search Params
    search_params = {
        "c2": 1,  # TV/Episodes
        "c30": 1,  # Anime
        "c41": 1,  # TV/Packs
        "c49": 1,  # TV/HD
        "c50": 1,  # TV/Sports
        "c52": 1,  # TV/B-Ray
        "c55": 1,  # TV/Kids
        "search": "",
    }

    # Units
    units = ["B", "KB", "MB", "GB", "TB", "PB"]

    def process_column_header(td):
        result = ""
        if td.a and td.a.img:
            result = td.a.img.get("alt", td.a.get_text(strip=True))
        if td.img and not result:
            result = td.img.get("alt", "")
        if not result:
            result = td.get_text(strip=True)
        return result

    if self.freeleech:
        search_params["freeleech"] = "on"

    for mode in search_strings:
        items = []
        logger.log("Search Mode: {}".format(mode), logger.DEBUG)

        for search_string in search_strings[mode]:
            if mode != "RSS":
                logger.log(
                    "Search string: {}".format(search_string.decode("utf-8")),
                    logger.DEBUG,
                )

            search_params["search"] = search_string

            data = self.get_url(
                self.urls["search"], params=search_params, returns="text"
            )
            if not data:
                continue

            with BS4Parser(data, "html5lib") as html:
                torrent_table = html.find("div", class_="boxContent")
                torrent_table = torrent_table.find("table") if torrent_table else None
                torrent_rows = torrent_table("tr") if torrent_table else []

                # Continue only if at least one Release is found
                if len(torrent_rows) < 2:
                    logger.log(
                        "Data returned from provider does not contain any torrents",
                        logger.DEBUG,
                    )
                    continue

                labels = [
                    process_column_header(label) for label in torrent_rows[0]("th")
                ]

                # Skip column headers
                for result in torrent_rows[1:]:
                    try:
                        cells = result("td")

                        title = (
                            cells[labels.index("Title")]
                            .find("a", class_="torrent")
                            .get_text()
                        )
                        download_url = urljoin(
                            self.url,
                            cells[labels.index("Download")]
                            .find(title="Download")
                            .parent["href"],
                        )
                        if not all([title, download_url]):
                            continue

                        seeders = try_int(
                            cells[labels.index("Seeders")].get_text(strip=True)
                        )
                        leechers = try_int(
                            cells[labels.index("Leechers")].get_text(strip=True)
                        )

                        # Filter unseeded torrent
                        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

                        torrent_size = cells[labels.index("Size")].get_text()
                        torrent_size = torrent_size[:-2] + " " + torrent_size[-2:]
                        size = convert_size(torrent_size, units=units) or -1

                        item = {
                            "title": title,
                            "link": download_url,
                            "size": size,
                            "seeders": seeders,
                            "leechers": leechers,
                            "pubdate": None,
                            "hash": None,
                        }
                        if mode != "RSS":
                            logger.log(
                                "Found result: %s with %s seeders and %s leechers"
                                % (title, seeders, leechers),
                                logger.DEBUG,
                            )

                        items.append(item)
                    except StandardError:
                        continue

        # For each search mode sort all the items by seeders if available
        items.sort(key=lambda d: try_int(d.get("seeders", 0)), reverse=True)
        results += items

    return results