This example code demonstrate to store device(key) and id(value) pair in a dictionary.
import requests from bs4 import BeautifulSoup USERNAME_SC = 'admin' PASSWORD_SC = 'p@ssw0rd' TUFIN_ST_API_BASE = "https://secure_track/securetrack/api/" TUFIN_SC_API_BASE = "https://secure_change/securechangeworkflow/api/securechange/" devices = {} devices_id = [] i = 0 tufin_sc = requests.session() tufin_sc.verify = False tufin_sc.auth = requests.auth.HTTPBasicAuth(USERNAME_SC, PASSWORD_SC) tufin_sc.headers.update({'Content-type': 'application/xml'}) response = tufin_sc.get(TUFIN_SC_API_BASE + "devices") soup = BeautifulSoup(response.text, 'html.parser') for id in soup.find_all('id'): devices_id.append(id.text) for name in soup.find_all('name'): devices[name.text] = devices_id[i] i += 1 print(devices)