Last active
April 7, 2021 08:25
-
-
Save lykkin/3a883f83877d6ad6e7d62285b38cc407 to your computer and use it in GitHub Desktop.
idk my bff xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
namespace_pattern = re.compile('{(?P<ns>[^}]*}') | |
def process_node(node, cb): | |
url = None | |
ns = namespace_pattern.match(node.tag) | |
if ns is not None: | |
url = ns.groupdict()['ns'] | |
if 'href' in node.attrib: | |
url = node.attrib['href'] | |
if url is not None: | |
cb(url, node) | |
for child in node: | |
process_node(child, cb) | |
def test(url, node): | |
print(url, node.tag) | |
process_node(root, test) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment