parse .xml with prefix's on tags? xml.etree.ElementTree

前端 未结 2 1675
无人及你
无人及你 2021-01-06 09:59

I can read tags, except when there is a prefix. I\'m not having luck searching SO for a previous question.

I need to read media:content. I tried i

2条回答
  •  囚心锁ツ
    2021-01-06 10:59

    Here's an example of using XML namespaces with ElementTree:

    >>> x = '''\
    
      Popular  Photography in the last 1 week
      
        foo
        photography/misc
        
      
       ... 
    
    '''
    >>> node = ElementTree.fromstring(x)
    >>> for elem in node.findall('item/{http://www.w3.org/TR/html4/}category'):
            print elem.text
    
    
    photography/misc
    

提交回复
热议问题