    def extract(self, html_contents, css_contents=None, base_url=None):
        """
        Extracts the cleaned html tree as a string and only
        css rules matching the cleaned html tree

        :param html_contents: The HTML contents to parse
        :type html_contents: str
        :param css_contents: The CSS contents to parse
        :type css_contents: str
        :param base_url: The base page URL to use for relative to absolute links
        :type base_url: str

        :returns: cleaned HTML contents, cleaned CSS contents
        :rtype: str or tuple
        """
        # Clean HTML
        html_extractor = self.html_extractor(
            html_contents, self._xpaths_to_keep, self._xpaths_to_discard)
        has_matches = html_extractor.parse()

        if has_matches:

            # Relative to absolute URLs
            if base_url is not None:
                html_extractor.rel_to_abs(base_url)

            # Convert ElementTree to string
            cleaned_html = html_extractor.to_string()

        else:
            cleaned_html = None

        # Clean CSS
        if css_contents is not None:

            if cleaned_html is not None:

                css_extractor = self.css_extractor(css_contents, cleaned_html)
                css_extractor.parse()

                # Relative to absolute URLs
                if base_url is not None:
                    css_extractor.rel_to_abs(base_url)

                cleaned_css = css_extractor.to_string()

            else:
                cleaned_css = None

        else:
            return cleaned_html

        return (cleaned_html, cleaned_css)