Spaces:
Sleeping
Sleeping
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>Web Scraper - Extract Data to Excel</title> | |
| <style> | |
| * { | |
| margin: 0; | |
| padding: 0; | |
| box-sizing: border-box; | |
| } | |
| body { | |
| font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; | |
| background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); | |
| min-height: 100vh; | |
| display: flex; | |
| justify-content: center; | |
| align-items: center; | |
| padding: 20px; | |
| } | |
| .container { | |
| background: white; | |
| border-radius: 20px; | |
| box-shadow: 0 20px 60px rgba(0,0,0,0.3); | |
| padding: 40px; | |
| max-width: 600px; | |
| width: 100%; | |
| } | |
| h1 { | |
| color: #333; | |
| margin-bottom: 10px; | |
| font-size: 28px; | |
| } | |
| .subtitle { | |
| color: #666; | |
| margin-bottom: 30px; | |
| font-size: 14px; | |
| } | |
| .form-group { | |
| margin-bottom: 25px; | |
| } | |
| label { | |
| display: block; | |
| color: #555; | |
| font-weight: 600; | |
| margin-bottom: 8px; | |
| } | |
| input[type="text"] { | |
| width: 100%; | |
| padding: 12px 15px; | |
| border: 2px solid #e0e0e0; | |
| border-radius: 8px; | |
| font-size: 15px; | |
| transition: border-color 0.3s; | |
| } | |
| input[type="text"]:focus { | |
| outline: none; | |
| border-color: #667eea; | |
| } | |
| .radio-group { | |
| display: flex; | |
| gap: 20px; | |
| margin-top: 10px; | |
| } | |
| .radio-item { | |
| display: flex; | |
| align-items: center; | |
| gap: 8px; | |
| } | |
| input[type="radio"] { | |
| width: 18px; | |
| height: 18px; | |
| cursor: pointer; | |
| } | |
| button { | |
| width: 100%; | |
| padding: 14px; | |
| background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); | |
| color: white; | |
| border: none; | |
| border-radius: 8px; | |
| font-size: 16px; | |
| font-weight: 600; | |
| cursor: pointer; | |
| transition: transform 0.2s, box-shadow 0.2s; | |
| } | |
| button:hover { | |
| transform: translateY(-2px); | |
| box-shadow: 0 10px 20px rgba(102, 126, 234, 0.4); | |
| } | |
| button:disabled { | |
| background: #ccc; | |
| cursor: not-allowed; | |
| transform: none; | |
| } | |
| .result { | |
| margin-top: 25px; | |
| padding: 20px; | |
| border-radius: 8px; | |
| display: none; | |
| } | |
| .result.success { | |
| background: #d4edda; | |
| border: 1px solid #c3e6cb; | |
| color: #155724; | |
| } | |
| .result.error { | |
| background: #f8d7da; | |
| border: 1px solid #f5c6cb; | |
| color: #721c24; | |
| } | |
| .download-btn { | |
| margin-top: 15px; | |
| background: #28a745; | |
| display: inline-block; | |
| padding: 10px 20px; | |
| text-decoration: none; | |
| border-radius: 5px; | |
| color: white; | |
| font-weight: 600; | |
| } | |
| .loader { | |
| display: none; | |
| text-align: center; | |
| margin-top: 20px; | |
| } | |
| .spinner { | |
| border: 4px solid #f3f3f3; | |
| border-top: 4px solid #667eea; | |
| border-radius: 50%; | |
| width: 40px; | |
| height: 40px; | |
| animation: spin 1s linear infinite; | |
| margin: 0 auto; | |
| } | |
| @keyframes spin { | |
| 0% { transform: rotate(0deg); } | |
| 100% { transform: rotate(360deg); } | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <div class="container"> | |
| <h1>🔍 Web Scraper Tool</h1> | |
| <p class="subtitle">Extract data from websites and download as Excel</p> | |
| <form id="scraperForm"> | |
| <div class="form-group"> | |
| <label for="url">Website URL</label> | |
| <input | |
| type="text" | |
| id="url" | |
| name="url" | |
| placeholder="https://example.com" | |
| required | |
| > | |
| </div> | |
| <div class="form-group"> | |
| <label>What to Extract?</label> | |
| <div class="radio-group"> | |
| <div class="radio-item"> | |
| <input type="radio" id="table" name="mode" value="table" checked> | |
| <label for="table">Tables</label> | |
| </div> | |
| <div class="radio-item"> | |
| <input type="radio" id="links" name="mode" value="links"> | |
| <label for="links">Links</label> | |
| </div> | |
| <div class="radio-item"> | |
| <input type="radio" id="products" name="mode" value="products"> | |
| <label for="products">Products</label> | |
| </div> | |
| </div> | |
| </div> | |
| <button type="submit" id="submitBtn">Extract Data</button> | |
| </form> | |
| <div class="loader" id="loader"> | |
| <div class="spinner"></div> | |
| <p>Extracting data...</p> | |
| </div> | |
| <div class="result" id="result"></div> | |
| </div> | |
| <script> | |
| document.getElementById('scraperForm').addEventListener('submit', async (e) => { | |
| e.preventDefault(); | |
| const url = document.getElementById('url').value; | |
| const mode = document.querySelector('input[name="mode"]:checked').value; | |
| const submitBtn = document.getElementById('submitBtn'); | |
| const loader = document.getElementById('loader'); | |
| const result = document.getElementById('result'); | |
| // Reset result | |
| result.style.display = 'none'; | |
| result.className = 'result'; | |
| // Show loader | |
| submitBtn.disabled = true; | |
| loader.style.display = 'block'; | |
| try { | |
| const response = await fetch('/scrape', { | |
| method: 'POST', | |
| headers: { | |
| 'Content-Type': 'application/json', | |
| }, | |
| body: JSON.stringify({ url, mode }) | |
| }); | |
| if (!response.ok) { | |
| throw new Error('Failed to extract data'); | |
| } | |
| // Get the blob | |
| const blob = await response.blob(); | |
| // Create download link | |
| const downloadUrl = window.URL.createObjectURL(blob); | |
| const a = document.createElement('a'); | |
| a.href = downloadUrl; | |
| a.download = 'scraped_data.xlsx'; | |
| document.body.appendChild(a); | |
| a.click(); | |
| window.URL.revokeObjectURL(downloadUrl); | |
| document.body.removeChild(a); | |
| // Show success message | |
| result.className = 'result success'; | |
| result.innerHTML = '✅ Data extracted successfully! Your download should start automatically.'; | |
| result.style.display = 'block'; | |
| } catch (error) { | |
| result.className = 'result error'; | |
| result.innerHTML = `❌ Error: ${error.message}. Please check the URL and try again.`; | |
| result.style.display = 'block'; | |
| } finally { | |
| submitBtn.disabled = false; | |
| loader.style.display = 'none'; | |
| } | |
| }); | |
| </script> | |
| </body> | |
| </html> |