Spaces:
Sleeping
Sleeping
Update templates/index.html
Browse files- templates/index.html +65 -69
templates/index.html
CHANGED
@@ -1,70 +1,66 @@
|
|
1 |
-
<!DOCTYPE html>
|
2 |
-
<html lang="en">
|
3 |
-
<head>
|
4 |
-
<meta charset="UTF-8">
|
5 |
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
-
<title>Web Scraper</title>
|
7 |
-
<
|
8 |
-
|
9 |
-
|
10 |
-
<
|
11 |
-
|
12 |
-
<
|
13 |
-
|
14 |
-
|
15 |
-
type="url"
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
type="
|
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 |
-
const data = await response.json();
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
}
|
67 |
-
});
|
68 |
-
</script>
|
69 |
-
</body>
|
70 |
</html>
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html lang="en">
|
3 |
+
<head>
|
4 |
+
<meta charset="UTF-8">
|
5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
+
<title>Web Scraper</title>
|
7 |
+
<link rel="stylesheet" href="/static/styles.css">
|
8 |
+
</head>
|
9 |
+
<body>
|
10 |
+
<div class="container">
|
11 |
+
<h1>Web Scraper</h1>
|
12 |
+
<form id="scrapeForm">
|
13 |
+
<div class="form-group">
|
14 |
+
<label for="url">Website URL:</label>
|
15 |
+
<input type="url" id="url" name="url" placeholder="https://example.com" required>
|
16 |
+
</div>
|
17 |
+
<div class="form-group">
|
18 |
+
<label for="bot_name">Bot Name:</label>
|
19 |
+
<input type="text" id="bot_name" name="bot_name" placeholder="MyDemoBot">
|
20 |
+
</div>
|
21 |
+
<div class="form-group">
|
22 |
+
<label for="nativemsg_token">NativeMSG API Token:</label>
|
23 |
+
<input type="password" id="nativemsg_token" name="nativemsg_token" placeholder="Enter your token">
|
24 |
+
</div>
|
25 |
+
<button type="submit">Scrape Website</button>
|
26 |
+
</form>
|
27 |
+
|
28 |
+
<h2>Scraped Data</h2>
|
29 |
+
<textarea id="response" readonly></textarea>
|
30 |
+
</div>
|
31 |
+
|
32 |
+
<script>
|
33 |
+
document.getElementById('scrapeForm').addEventListener('submit', async (event) => {
|
34 |
+
event.preventDefault();
|
35 |
+
|
36 |
+
const url = document.getElementById('url').value;
|
37 |
+
const bot_name = document.getElementById('bot_name').value || undefined;
|
38 |
+
const nativemsg_token = document.getElementById('nativemsg_token').value || undefined;
|
39 |
+
const responseArea = document.getElementById('response');
|
40 |
+
|
41 |
+
responseArea.value = 'Loading...';
|
42 |
+
|
43 |
+
try {
|
44 |
+
const queryParams = new URLSearchParams({ url, use_sample: false });
|
45 |
+
if (bot_name) queryParams.append('bot_name', bot_name);
|
46 |
+
if (nativemsg_token) queryParams.append('nativemsg_token', nativemsg_token);
|
47 |
+
|
48 |
+
const response = await fetch(`/scrape?${queryParams.toString()}`, {
|
49 |
+
method: 'GET',
|
50 |
+
headers: { 'Content-Type': 'application/json' }
|
51 |
+
});
|
52 |
+
|
53 |
+
if (!response.ok) {
|
54 |
+
throw new Error(`HTTP error! Status: ${response.status}`);
|
55 |
+
}
|
56 |
+
|
57 |
+
const data = await response.json();
|
58 |
+
responseArea.value = JSON.stringify(data, null, 2);
|
59 |
+
} catch (error) {
|
60 |
+
console.error('Error:', error);
|
61 |
+
responseArea.value = `Error: ${error.message}`;
|
62 |
+
}
|
63 |
+
});
|
64 |
+
</script>
|
65 |
+
</body>
|
|
|
|
|
|
|
|
|
66 |
</html>
|