1
我是ElementTree的新手。我試圖阻止XML響應中的<sid>
值。Python ElementTree找不到工作
以下代碼不適用於我。我如何提取<sid>
中的值?我不確定數字53
是從哪裏來的。
...
r = requests.post(self.dispatchurl, verify=False, auth=HTTPBasicAuth(self.user, self.passwd))
print r.content
tree = ET.ElementTree(r.content)
print tree.find('sid')
輸出:
/usr/bin/python2.7 /home/myuser/PycharmProjects/autoshun/shunlibs/SplunkSearch.py
<?xml version="1.0" encoding="UTF-8"?>
<response>
<sid>super__awesome__search__searchname_at_1489433276_24700</sid>
</response>
53
Process finished with exit code 0
這個數字*是在字符串*中首次出現''sid「'的位置。這應該是一個評論,說實話,我不知道如何得到''的價值,因爲我沒有任何'ElementTree'的經驗。 –
ForceBru