我无法使用atom-xml 解析和打印网页中集合类别的元素和属性。从下面的 Python 脚本中,“print(response.content)”列出了内容,包括: '''
"xmlns= <atom:category scheme="http://www.zooo.com/types"
term="changetimber/has-game"/>
Run Code Online (Sandbox Code Playgroud)
''' 并打印子标签:'''
{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
Run Code Online (Sandbox Code Playgroud)
'''
Python脚本py运行后,出现错误 ''' Children = hasgame.getchildren AttributeError: 'xml.etree.ElementTree.Element' object has no attribute 'getchildren' '''
并且不会打印以下 for 条件中的任何内容: ''' forcategory in root.findall('''.//@term="changetimber/hasgame" ] '''): print(category.attrib) '''
下面的Python脚本是:'''
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)
Run Code Online (Sandbox Code Playgroud)
'''
nas*_*jai 14
变成hasgame.getchildren()list(hasgame)
| 归档时间: |
|
| 查看次数: |
13904 次 |
| 最近记录: |