1 names = root.findall(".//")2for name in names:3print(name)
これを実行すると、以下のような結果が得られます。
bash
1<Element '{http://uniprot.org/uniprot}entry' at 0x10cbcbbd8>2<Element '{http://uniprot.org/uniprot}accession' at 0x10cbd41d8>3<Element '{http://uniprot.org/uniprot}accession' at 0x10cc18c28>4<Element '{http://uniprot.org/uniprot}name' at 0x10cc18c78>5<Element '{http://uniprot.org/uniprot}protein' at 0x10cc38318>6<Element '{http://uniprot.org/uniprot}recommendedName' at 0x10cc56318>7
すでに回答が出ていますが、これを見ると、要素の前に名前空間が付与されていることがわかります。
python
1 names = root.find(".//uniport:protein",{'uniport':'http://uniprot.org/uniprot'})2for name in names:3print(name)
上のように名前空間をつけて検索してあげると、以下の結果が得られます。
bash
1<Element '{http://uniprot.org/uniprot}protein' at 0x107fe1318>2<Element '{http://uniprot.org/uniprot}recommendedName' at 0x107fff318>3<Element '{http://uniprot.org/uniprot}fullName' at 0x107fff368>4<Element '{http://uniprot.org/uniprot}alternativeName' at 0x107fff4f8>5<Element '{http://uniprot.org/uniprot}fullName' at 0x107fff548>6<Element '{http://uniprot.org/uniprot}alternativeName' at 0x107fff638>7<Element '{http://uniprot.org/uniprot}fullName' at 0x107fff688>8<Element '{http://uniprot.org/uniprot}alternativeName' at 0x107fff6d8>9<Element '{http://uniprot.org/uniprot}fullName' at 0x107fff728>10<Element '{http://uniprot.org/uniprot}alternativeName' at 0x107fff7c8>11<Element '{http://uniprot.org/uniprot}fullName' at 0x107fff818>12<Element '{http://uniprot.org/uniprot}alternativeName' at 0x107fff8b8>13<Element '{http://uniprot.org/uniprot}fullName' at 0x107fff908>14<Element '{http://uniprot.org/uniprot}alternativeName' at 0x107fff958>15<Element '{http://uniprot.org/uniprot}fullName' at 0x107fff9a8>16<Element '{http://uniprot.org/uniprot}alternativeName' at 0x107fff9f8>17<Element '{http://uniprot.org/uniprot}fullName' at 0x107fffa48>18<Element '{http://uniprot.org/uniprot}alternativeName' at 0x107fffae8>19<Element '{http://uniprot.org/uniprot}fullName' at 0x107fffb38>20