Вы можете использовать BeautifulSoup .Я думаю, что это будет делать то, что вы хотите:
from bs4 import BeautifulSoup
def get_by_type(data, some_type):
soup = BeautifulSoup(data, 'xml')
components = soup.find('result').find_all('address_component')
for c in components:
if any(t for t in c.find_all('type') if t.text == some_type):
return c.long_name.text
with open('data.xml') as f:
data = f.read()
print(get_by_type(data, 'postal_code'))
Вы можете получить другие значения, просто изменив строку, заданную в качестве второго аргумента, на get_by_type
.