Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1

Thread: Parsing an XML

  1. #1
    New to the CF scene
    Join Date
    Jun 2018
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Parsing an XML

    As a pretty new Python learner, I have set myself a mini project to parse the highways England xml file. so far my code is:

    Code:
    #!/usr/bin/python 
    
    #rrvar = "steve"
    #print rrvar
    
    import urllib2
    varresponse = urllib2.urlopen('http://m.highwaysengland.co.uk/feeds/rss/AllEvents.xml')
    
    from xml.etree import ElementTree as et
    tree = et.parse(varresponse)
    
    root = tree.getroot()
    
    for item in root:
            print(item.tag, item.attrib)
            
    
    for author in root.iter('author'):
            print author
    when I run this in terminal it only prints the word author but I want it to print everything within the author bracket if that makes any sense. if anyone could give me any advice on what to change I would be so grateful,
    cheers guys
    Last edited by Alex Vincent; Jun 29th, 2018 at 10:01 PM. Reason: adding code tags


 

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •