<!DOCTYPE html> <html lang="pl"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Pobieranie danych z UniProt API</title> <style> body { font-family: Arial, sans-serif; margin: 20px; } input, button { padding: 10px; margin: 10px 0; width: 100%; } #results div { margin-bottom: 20px; padding: 10px; border: 1px solid #ccc; } </style> </head> <body> <h1>Pobieranie danych z UniProt API</h1> <form id="searchForm"> <label for="keyword">Wprowadź słowo kluczowe (np. hemoglobina):</label> <input type="text" id="keyword" placeholder="np. hemoglobin" required> <button type="submit">Szukaj</button> </form> <h2>Wyniki:</h2> <div id="results">Tutaj pojawią się wyniki...</div> <script src="script.js"></script> </body> </html>
<script> // Pobieranie danych z UniProt API const fetchProteinData = async (keyword) => { const url = `https://rest.uniprot.org/uniprotkb/search?query=${keyword}&format=json&size=5`; try { const response = await fetch(url); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } const data = await response.json(); displayResults(data.results); } catch (error) { console.error('Błąd podczas pobierania danych:', error); } }; // Wyświetlanie danych w przeglądarce const displayResults = (results) => { const resultsDiv = document.getElementById('results'); resultsDiv.innerHTML = ''; results.forEach((entry) => { const div = document.createElement('div'); div.innerHTML = ` <h3>${entry.primaryAccession}</h3> <p><strong>Organizm:</strong> ${entry.organism.scientificName}</p> <p><strong>Nazwa białka:</strong> ${entry.proteinDescription.recommendedName.fullName.value}</p> `; resultsDiv.appendChild(div); }); }; // Event listener dla formularza document.getElementById('searchForm').addEventListener('submit', (e) => { e.preventDefault(); const keyword = document.getElementById('keyword').value; fetchProteinData(keyword); }); </script>