We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Detect HTML Attributes
Detect HTML Attributes
Sort by
recency
|
106 Discussions
|
Please Login in order to post a comment
Interesting approach! Just curious — how are you handling self-closing tags like
or and attributes that might appear in different orders? Are you using a parser like HTMLParser or regular expressions for extraction?
Regards, https://halfbirthdaycal.com/
The exact code will be: import re
Read input
N = int(raw_input()) html = '' for _ in range(N): html += raw_input()
Extract tags and attributes using regex
tags = {} pattern = r'<(\w+)([^>]*)>' matches = re.findall(pattern, html)
for match in matches: tag, attrs = match if tag not in tags: tags[tag] = set()
Print output
for tag in sorted(tags): if tag == 'a': attrs = ','.join(sorted([attr for attr in tags[tag] if attr in ['accesskey', 'href', 'title']])) else: attrs = ','.join(sorted(tags[tag]))
Java 15
TreeMap holds tag and corresponding attributes as list
Regex for tag :
Regex for attribute :
Python 3