import requests import csv headers = { 'Accept': 'application/json, text/plain, */*', 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36', 'X-Api-Key': 'pJnKrR6B3FzRNFsF33xL8LhSs55KPJrm', 'X-Momentum-Client': 'momentum.se-fastighetminasidor', 'X-Momentum-Client-Id': 'EAP-47356', 'X-Momentum-Client-Version': '5.20.3.15457', 'X-Momentum-Device-Key': 'e8q66tgd9jsqalnk9alijf', } url = "https://tunabyggen-fastighet.momentum.se/Prod/Tunabyggen/PmApi/v2/market/objects?type=parking&limit=500" response = requests.get(url, headers=headers) data = response.json() csv_filename = "garages.csv" csv_columns = ["id", "displayName", "description", "price", "completeAddress"] with open(csv_filename, 'w', newline='', encoding='utf-8') as csvfile: writer = csv.DictWriter(csvfile, fieldnames=csv_columns) writer.writeheader() for item in data["items"]: if item.get("thumbnail", {}).get("exists") and item["thumbnail"]["displayName"] == "Garage bild": garage_id = item["id"] display_name = item["displayName"] description = item["description"] price = item["pricing"]["price"] detail_url = f"https://tunabyggen-fastighet.momentum.se/Prod/Tunabyggen/PmApi/v2/market/objects/{garage_id}" detail_response = requests.get(detail_url, headers=headers) detail_data = detail_response.json() complete_address = detail_data.get("location", {}).get("address", {}).get("completeAdress", "") print(complete_address) writer.writerow({ "id": garage_id, "displayName": display_name, "description": description, "price": price, "completeAddress": complete_address }) print(f"Data has been written to {csv_filename}")