Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
Ask Question
I am not able parse and print elements and attributes from a collection category from web page using atom-xml. From the Python script below, the "print(response.content)" lists contents ok and includes:
"xmlns= <atom:category scheme="http://www.zooo.com/types"
term="changetimber/has-game"/>
And prints child tags ok:
{http://www.w3.org/2007/app}workspace
{http://www.w3.org/2005/Atom}title
{http://www.w3.org/2007/app}collection
{http://www.w3.org/2005/Atom}title
{http://www.w3.org/2007/app}categories
{http://www.w3.org/2005/Atom}category
After the Python script py is ran, get error
children = hasgame.getchildren
AttributeError: 'xml.etree.ElementTree.Element' object has no attribute
'getchildren'
And does not print anything from the for condition below:
for category in root.findall('''.//@term="changetimber/hasgame" ] '''):
print(category.attrib)
The Python script below is:
import requests
from requests.auth import HTTPBasicAuth
import xml.etree.cElementTree as ET
url = 'http://ipaddress/mygame'
response = requests.get(url, auth=HTTPBasicAuth('user','pass'))
print(response)
print("***********list response content ******************")
print(response.content)
print("******** Display child tags********")
root = ET.fromstring(response.content)
for child in root.iter('*'):
print(child.tag)
# Create a dictionary
xmlDictionary = {}
for hasgame in root:
children = hasgame.getchildren()
xmlDictionary[children[0].text] = children[1].text
print("******** print dictionary ******")
print(xmlDictionary)
for category in root.findall('''.//@term="changetimber/hasgame" ] '''):
print(category.attrib)
–
–
–
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.