<commit_before>from lxml.html import parse, fromstring

from comics.aggregator.exceptions import CrawlerError

class LxmlParser(object):
    def __init__(self, url=None, string=None):
        if url is not None:
            self.root = parse(url).getroot()
            self.root.make_links_absolute(url)
        elif string is not None:
            if len(string) == 0:
                string = '<xml />'
            self.root = fromstring(string)
        else:
            raise LxmlParserException()

    def text(self, selector, default=None):
        try:
            return self.select(selector).text_content()
        except LxmlParserException:
            if default is not None:
                return default
            raise

    def src(self, selector, default=None):
        try:
            return self.select(selector).get('src')
        except LxmlParserException:
            if default is not None:
                return default
            raise

    def alt(self, selector, default=None):
        try:
            return self.select(selector).get('alt')
        except LxmlParserException:
            if default is not None:
                return default
            raise

    def title(self, selector, default=None):
        try:<commit_msg>Error message for corner case in lxmlparser<commit_after>from lxml.html import parse, fromstring

from comics.aggregator.exceptions import CrawlerError

class LxmlParser(object):
    def __init__(self, url=None, string=None):
        if url is not None:
            self.root = parse(url).getroot()
            self.root.make_links_absolute(url)
        elif string is not None:
            if len(string) == 0:
                string = '<xml />'
            self.root = fromstring(string)
        else:
            raise LxmlParserException('Parser need URL or string to operate on')

    def text(self, selector, default=None):
        try:
            return self.select(selector).text_content()
        except LxmlParserException:
            if default is not None:
                return default
            raise

    def src(self, selector, default=None):
        try:
            return self.select(selector).get('src')
        except LxmlParserException:
            if default is not None:
                return default
            raise

    def alt(self, selector, default=None):
        try:
            return self.select(selector).get('alt')
        except LxmlParserException:
            if default is not None:
                return default
            raise

    def title(self, selector, default=None):
        try:
{'fraction_non_alphanumeric': 0.08061420345489444, 'fraction_numerical': 0.0007677543186180423, 'mean_word_length': 1.8449781659388647, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 15}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3604574', 'n_tokens_mistral': 674, 'n_tokens_neox': 651, 'n_words': 200}