<?php
require_once('simple_html_dom.php');
// Define URLs to scrape
$urls = array("https://www.example.com", "https://www.another-example.com");
// Create empty array to hold scraped data
$scraped_data = array();
// Loop through each URL and scrape data
foreach ($urls as $url) {
// Send HTTP request to website and get response
$response = file_get_html($url);
// Parse HTML content of response using Simple HTML DOM
$dom = str_get_html($response);
// Extract relevant data from HTML using Simple HTML DOM's methods
// In this example, we are just extracting the page title
$page_title = $dom->find('title', 0)->innertext;
// Add extracted data to array of scraped data
array_push($scraped_data, $page_title);
}
// Write scraped data to file
$file = fopen("scrap-data.txt", "w");
foreach ($scraped_data as $data) {
fwrite($file, $data . "\n");
}
fclose($file);
?>
|