PHP Classes

PHP Website Downloader: Download pages and files of a site to local files

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2024-02-21 (7 months ago) RSS 2.0 feedNot enough user ratingsTotal: 97 This week: 1All time: 9,848 This week: 44Up
Version License PHP version Categories
websitedownloader 1.0.0The PHP License5HTML, Files and Folders, Web services, P...
Description 

Author

This package can download pages and files of a site to local files.

It can take the URL of a site and download the HTML of the page to a local file.

The package can also parse the HTML to extract the URLs of other page files like the images, icons, CSS, and JavaScript.

Picture of Cedric Maenetja
  Performance   Level  
Name: Cedric Maenetja is available for providing paid consulting. Contact Cedric Maenetja .
Classes: 4 packages by
Country: South Africa South Africa
Age: ???
All time rank: 387621 in South Africa South Africa
Week rank: 49 Up1 in South Africa South Africa Up
Innovation award
Innovation award
Nominee: 1x

Winner: 1x

Recommendations

What is the best PHP website crawler class?
Download a complete website to local storage

Example

<?php

   
require ('WebsiteDownloader.php');

   
$downloader = new WebsiteDownloader([
       
'domain' => 'https://example.com',
       
'output_dir' => 'local_files'
   
]);

   
$downloader->download();
   
$downloader->downloadAssetFromURL('https://example.com/index.html');

?>


Details

Website Downloader

This PHP class, WebsiteDownloader, is designed to download various assets (HTML files, CSS files, JavaScript files, images, etc.) from a given website. It provides methods to download specific types of assets or all assets at once.

Usage

Instantiate the WebsiteDownloader class by providing the required parameters: the domain of the website to download from and the output directory where the downloaded files will be saved.

$downloader = new WebsiteDownloader([
    'domain' => 'https://example.com',
    'output_dir' => '/path/to/output/directory'
]);

Methods

  • download($asset): Downloads the specified type of asset. If no asset type is provided, it downloads all assets. Supported asset types are 'html', 'css', 'js', and 'img'.
  • downloadAssetFromURL($url): Downloads a specific asset from the provided URL.

Example

download($asset);

Downloading a specified type of asset from the given domain.

try {
    // downloads all assets (html, css, js, images, etc)
    $downloader->download();

    // download html
    $downloader->download('html');

    // download js
    $downloader->download('js');
    
    // download css (this will include favicons if found)
    $downloader->download('css');

    // download images
    $downloader->download('img');

} catch (InvalidArgumentException $e) {
    echo "Error: " . $e->getMessage();
}

downloadAssetFromURL($href);

Downloads a specific asset from the provided URL

// downloads the index.html file
// you can pass any file in the url to download such as images, js, css, etc
$downloader->downloadAssetFromURL('https://example.com/index.html');

Requirements

  • PHP 7.0 or higher
  • cURL extension enabled

Note

  • This class uses cURL to download files from the website. Make sure cURL extension is enabled in your PHP configuration.
  • Be cautious while using this class to avoid downloading files from unauthorized websites or violating terms of service.
  • Downloading files from a website may not always be possible due to restrictions set by the website owner or technical limitations in its design.

Author

This PHP class was created by Yung Cet (Cedric Maenetja).

License

This PHP class is released under the MIT License. See the LICENSE file for details.


  Files folder image Files (4)  
File Role Description
Accessible without login Plain text file demo.php Example Example script
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file README.md Doc. Documentation
Plain text file WebsiteDownloader.php Class Class source

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:97
This week:1
All time:9,848
This week:44Up