68 lines
2.0 KiB
HTML
68 lines
2.0 KiB
HTML
{% extends "base.html" %} {% block title %}Scrape Jobs{% endblock %} {% block
|
|
content %}
|
|
<div id="scrape-container">
|
|
<h2>Job Scraping Progress</h2>
|
|
<button id="start-scrape" onclick="startScrape()">Start Scraping</button>
|
|
<div
|
|
id="output"
|
|
style="
|
|
margin-top: 20px;
|
|
padding: 10px;
|
|
border: 1px solid #ccc;
|
|
height: 400px;
|
|
overflow-y: auto;
|
|
background-color: #f9f9f9;
|
|
font-family: monospace;
|
|
white-space: pre-wrap;
|
|
"
|
|
></div>
|
|
</div>
|
|
{% endblock %} {% block scripts %}
|
|
<script>
|
|
function startScrape() {
|
|
const output = document.getElementById("output");
|
|
const startButton = document.getElementById("start-scrape");
|
|
|
|
output.textContent = "Starting scrape...\n";
|
|
startButton.disabled = true;
|
|
startButton.textContent = "Scraping...";
|
|
|
|
fetch("/scrape")
|
|
.then((response) => {
|
|
const reader = response.body.getReader();
|
|
const decoder = new TextDecoder();
|
|
|
|
function readStream() {
|
|
reader
|
|
.read()
|
|
.then(({ done, value }) => {
|
|
if (done) {
|
|
output.textContent += "\nScraping completed!";
|
|
startButton.disabled = false;
|
|
startButton.textContent = "Start Scraping";
|
|
return;
|
|
}
|
|
|
|
const chunk = decoder.decode(value, { stream: true });
|
|
output.textContent += chunk;
|
|
output.scrollTop = output.scrollHeight;
|
|
readStream();
|
|
})
|
|
.catch((error) => {
|
|
output.textContent += `\nError: ${error.message}`;
|
|
startButton.disabled = false;
|
|
startButton.textContent = "Start Scraping";
|
|
});
|
|
}
|
|
|
|
readStream();
|
|
})
|
|
.catch((error) => {
|
|
output.textContent = `Error starting scrape: ${error.message}`;
|
|
startButton.disabled = false;
|
|
startButton.textContent = "Start Scraping";
|
|
});
|
|
}
|
|
</script>
|
|
{% endblock %}
|