예제 #1
0
def parse_html_tag(html, closeable=False):
    regex = r'<([a-z]+)\s?([^<]*)>'

    if closeable:
        regex += r'(.*)</([^>]*)>'
        match = re.search(regex, html)
        return match.group(1), parse_attrs(match.group(2)), match.group(3)

    match = re.search(regex, html)
    return match.group(1), parse_attrs(match.group(2))
예제 #2
0
def parse_html_options(html):
    option_re = re.compile(r'<option\s?([^<]*)>([^>]*)</option>')
    options = []

    for line in split_tags(html):
        match = option_re.search(line)

        if match:
            options.append({
                'attrs': parse_attrs(match.group(1), order=False),
                'content': match.group(2),
            })

    return options
예제 #3
0
 def test_parse_attrs(self):
     test_str = 'color="red" edit font-size="12" required'
     expect = dict(color='red', font_size='12', required=True, edit=True)
     self.assertDictEqual(parse_attrs(test_str), expect)