Can PHP be used to download a website and extract specific text content?

To download a website and extract specific text content using PHP, you can utilize the cURL library to fetch the website's HTML code and then use DOMDocument or regular expressions to extract the desired text content from the HTML.

<?php
// URL of the website to download
$url = 'https://www.example.com';

// Initialize cURL session
$curl = curl_init($url);

// Set cURL options to fetch the website content
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$html = curl_exec($curl);

// Close cURL session
curl_close($curl);

// Create a DOMDocument object and load the HTML content
$dom = new DOMDocument();
$dom->loadHTML($html);

// Extract specific text content using DOMXPath or other methods
$xpath = new DOMXPath($dom);
$elements = $xpath->query('//p[@class="content"]');

foreach ($elements as $element) {
    echo $element->nodeValue . "\n";
}
?>