我有一个
形式的公钥xml字符串<RSAPublicKey> <Modulus>ANG9SxVyOA8IX9mRi5Q6sH/z04fvrsLLrAf3ooAGRiETNB1TZfZ/ZWhpw9RLYPcf3J+kaqQneHEMS9OGuIYxa0rUwVYtKjSjRp8y+XNm3sODNqD4zPjqMh6wThOug5Gg/M1+ZXlkXvszmAwiXlImDqp2nH+ZFVnrREVZ1U7WKUc5</Modulus><Exponent>AQAB</Exponent></RSAPublicKey>.
如何在Python中从此xml字符串中提取模数?例如手术后我应该ANG9SxVyOA8IX9mRi5Q6sH/z04fvrsLLrAf3ooAGRiETNB1TZfZ/ZWhpw9RLYPcf3J+kaqQneHEMS9OGuIYxa0rUwVYtKjSjRp8y+XNm3sODNqD4zPjqMh6wThOug5Gg/M1+ZXlkXvszmAwiXlImDqp2nH+ZFVnrREVZ1U7WKUc5
。
提前致谢!
答案 0 :(得分:1)
您可以使用元素树。
import xml.etree.ElementTree as ET
root = ET.ElementTree(file="yourxml.xml")
RSAPublicKey = root.findall("./RSAPublicKey") # this search all RSAPublickey
for item in RSAPublicKey :
Modulus= item .findall("./Modulus") #in rsapublic key modulus
print Modulus