fix: update scrape function to handle HTML response and improve status messages
This commit is contained in:
@@ -41,12 +41,16 @@ function scrape(event) {
|
||||
event.preventDefault(); // Prevent the default form submission
|
||||
updateScrapeInfo("Scraping in progress...", "blue");
|
||||
fetch("/scrape")
|
||||
.then((response) => response.json())
|
||||
// expect HTML response containing "Scraping completed successfully!"
|
||||
.then((response) => response.text())
|
||||
.then((data) => {
|
||||
if (data.status) {
|
||||
updateScrapeInfo(data.status, "green");
|
||||
if (data.includes("Scraping completed successfully!")) {
|
||||
updateScrapeInfo("Scraping completed successfully!", "green");
|
||||
} else {
|
||||
updateScrapeInfo("Scraping failed. Please try again.", "red");
|
||||
updateScrapeInfo(
|
||||
"Scraping failed or timed out. Please try again.",
|
||||
"red"
|
||||
);
|
||||
}
|
||||
})
|
||||
.catch((error) => console.error("Error:", error));
|
||||
|
||||
Reference in New Issue
Block a user