0
    import requests
    import xml.etree.ElementTree as ET


    def abc(area_code, office_code): 
        args = area_code + office_code
     url = (described bellow)
     r = requests.get(url=url)
     tree=ET.ElementTree()
     parsed_data=tree.parse(r.content)
      return parsed_data

   abc('503', '402')

where url is

url="http://www.networksolutions.ds.adp.com/NSPhoneToolDB/template/GetBusRouteFilterExpressions.xml?"\
               "Telnum=" +args+ "&FilterNamePrefix=ORPORTCDK&ReturnResult=detail"

when i run this thing i am getting

<Element 'GetBusRouteFilterExpressions' at 0x7f2abf526f48>  

as output instead of entire file.

3 Answers 3

1

You're giving it the response object itself.

Try giving it the content of the response like so parsed_data=tree.parse(r.content).

Sign up to request clarification or add additional context in comments.

2 Comments

yes it worked but now it just prints <Element 'GetBusRouteFilterExpressions' at 0x7f952bfc3f48>
And what's the problem
1

When you make the request in python you're getting back a response object. You need to parse the body of that response instead. So

tree.parse(r.content)

Comments

0

Read and try the example from

The ElementTree XML API: 20.5.1.2. Parsing XML

As an Element, root has a tag and a dictionary of attributes:

    \>>> root.tag
    'data'
    \>>> root.attrib
    {}

It also has children nodes over which we can iterate:

    \>>> for child in root:
    ...     print(child.tag, child.attrib)
    ...
    country {'name': 'Liechtenstein'}
    country {'name': 'Singapore'}
    country {'name': 'Panama'}

Children are nested, and we can access specific child nodes by index:

   \ >>> root[0][1].text
    '2008'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.