-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscrape.php
More file actions
38 lines (35 loc) · 1.26 KB
/
scrape.php
File metadata and controls
38 lines (35 loc) · 1.26 KB
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
<?php
require_once 'includes/scraper.php';
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['url'])) {
$url = trim($_POST['url']);
$result = scrapeMetaData($url);
// Save result to JSON
if (!isset($result['error'])) {
$file = 'data/scrapedData.json';
$existing = file_exists($file) ? json_decode(file_get_contents($file), true) : [];
$existing[] = array_merge(['url' => $url], $result);
file_put_contents($file, json_encode($existing, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Scraping Results</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<h2>Scraping Result</h2>
<?php if (isset($result['error'])): ?>
<p style="color:red;">❌ <?= htmlspecialchars($result['error']) ?></p>
<?php else: ?>
<p><strong>Title:</strong> <?= htmlspecialchars($result['title']) ?></p>
<p><strong>Description:</strong> <?= htmlspecialchars($result['description']) ?></p>
<?php if ($result['image']): ?>
<img src="<?= htmlspecialchars($result['image']) ?>" alt="Image" width="200">
<?php endif; ?>
<?php endif; ?>
<br><a href="index.php">← Go back</a>
</body>
</html>