-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
49 lines (41 loc) · 1.56 KB
/
index.php
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
<?php
// Handling form submission
if (isset($_POST['query'])) {
$query = urlencode($_POST['query']);
$googleApiKey = 'Google_Custom_Search_API_Key';
$googleCx = 'Google_Custom_Search_Engine_ID';
$googleApiUrl = "https://www.googleapis.com/customsearch/v1?q=$query&key=$googleApiKey&cx=$googleCx&num=5";
// Making a request to the Google Custom Search API
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $googleApiUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$googleApiResponse = curl_exec($ch);
curl_close($ch);
$searchResults = json_decode($googleApiResponse, true)['items'];
// Scrape web pages using ScrapingBee API
$scrapingBeeApiKey = 'ScrapingBee_API_Key';
$scrapingBeeApiUrl = "https://app.scrapingbee.com/api/v1/?api_key=$scrapingBeeApiKey";
$scrapedResults = array();
foreach ($searchResults as $result) {
$url = $result['link'];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "$scrapingBeeApiUrl&url=$url");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_close($ch);
$scrapedResults[] = array(
'link' => $url,
);
}
}
?>
<!-- Create the HTML form -->
<form method="post">
<input type="text" name="query" placeholder="Enter your query">
<input type="submit" value="Search">
</form>
<!-- Display the results -->
<?php if (isset($scrapedResults)): ?>
<?php foreach ($scrapedResults as $result): ?>
<p href="<?php echo $result['link']; ?>"><?php echo $result['link']; ?></p>
<?php endforeach; ?>
<?php endif; ?>