Skip to content

Instantly share code, notes, and snippets.

@lykkin
Last active April 7, 2021 08:25
Show Gist options
  • Save lykkin/3a883f83877d6ad6e7d62285b38cc407 to your computer and use it in GitHub Desktop.
Save lykkin/3a883f83877d6ad6e7d62285b38cc407 to your computer and use it in GitHub Desktop.
idk my bff xml
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