私はhref
を以下のXMLから解析しようとしています。以下に複数のworkspace
タグがあります。私はちょうど1つを示します。Pythonが異常なタグ名(アトム:リンク)を持つXMLを解析します
<workspaces>
<workspace>
<name>practice</name>
<atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate" href="https://www.my-geoserver.com/geoserver/rest/workspaces/practice.xml" type="application/xml"/>
</workspace>
</workspaces>
上記リクエスト・ライブラリを使用してrequests.get
コマンドから来ている:
myUrl = 'https://www.my-geoserver.com/geoserver/rest/workspaces'
headers = {'Accept': 'text/xml'}
resp = requests.get(myUrl,auth=('admin','password'),headers=headers)
私は 'ワークスペース' を検索した場合、私はオブジェクトが返されます:
になりlst = tree.findall('workspace')
print(lst)
:
[<Element 'workspace' at 0x039E70F0>, <Element 'workspace' at 0x039E71B0>, <Element 'workspace' at 0x039E7240>]
、罰金[OK]をしかし、どのように私は、文字列のうち、テキストのhrefを得るか、私が試してみました:
lst = tree.findall('atom')
lst = tree.findall('atom:link')
lst = tree.findall('workspace/atom:link')
しかし、それらのどれもタグを隔離する働きません、実際には最後のものは、エラー
を作成しますSyntaxError: prefix 'atom' not found in prefix map
これらのタグ名でhrefのインスタンスをすべて取得するにはどうすればよいですか?私が見つけた
私は出力としてシンプルな[]を取得しました。resp.textの形式とは何か関係がありますが、これは私が知る限りテキストです。 y.workspaces.findAll( "workspace")を使用すると動作しますが、それは私が何をしたのかではありません。 –