Spaces:
Runtime error
Runtime error
File size: 4,257 Bytes
b83317e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | {% extends 'layout.html' %}
{% block title %}Web Scraper | Math Misconception Detector{% endblock %}
{% block content %}
<div class="container mt-5">
<div class="row">
<div class="col-12">
<div class="card mb-4 shadow-sm">
<div class="card-header bg-gradient">
<h1 class="mb-0">Web Scraper</h1>
</div>
<div class="card-body">
<p class="lead">Extract text content from any website URL using advanced NLP techniques.</p>
<form id="scrape-form" class="mb-4">
<div class="mb-3">
<label for="url" class="form-label">Website URL</label>
<div class="input-group">
<input type="url" class="form-control" id="url" name="url"
placeholder="https://example.com" required>
<button type="submit" class="btn btn-primary">
<i class="fas fa-spider me-2"></i> Scrape Content
</button>
</div>
<div class="form-text">Enter a complete URL including https://</div>
</div>
</form>
<div id="loading" class="text-center d-none">
<div class="spinner-border text-primary" role="status">
<span class="visually-hidden">Loading...</span>
</div>
<p class="mt-2">Extracting content, please wait...</p>
</div>
<div id="results" class="d-none">
<h4 class="mb-3">Extracted Content</h4>
<div class="card bg-light">
<div class="card-body">
<pre id="content-display" class="mb-0" style="white-space: pre-wrap;"></pre>
</div>
</div>
</div>
<div id="error-message" class="alert alert-danger d-none mt-3"></div>
</div>
</div>
</div>
</div>
</div>
{% endblock %}
{% block scripts %}
<script>
document.addEventListener('DOMContentLoaded', function() {
const scrapeForm = document.getElementById('scrape-form');
const loadingDiv = document.getElementById('loading');
const resultsDiv = document.getElementById('results');
const contentDisplay = document.getElementById('content-display');
const errorMessage = document.getElementById('error-message');
scrapeForm.addEventListener('submit', function(e) {
e.preventDefault();
// Get form data
const formData = new FormData(scrapeForm);
const url = formData.get('url');
// Reset previous results
resultsDiv.classList.add('d-none');
errorMessage.classList.add('d-none');
loadingDiv.classList.remove('d-none');
// Send request to server
fetch('/scrape', {
method: 'POST',
body: formData
})
.then(response => response.json())
.then(data => {
loadingDiv.classList.add('d-none');
if (data.status === 'success') {
contentDisplay.textContent = data.content;
resultsDiv.classList.remove('d-none');
} else {
errorMessage.textContent = data.message;
errorMessage.classList.remove('d-none');
}
})
.catch(error => {
loadingDiv.classList.add('d-none');
errorMessage.textContent = 'Error connecting to server. Please try again.';
errorMessage.classList.remove('d-none');
console.error('Error:', error);
});
});
});
</script>
{% endblock %} |