从单个网页下载所有图像

I'm experimenting with PHP, and I've just asked myself a question. How can I download all images from a single website? Let's say that I wanted and images from cnn.com or any other website. Is there any easy way I can download all the images using PHP, and save them on my local computer (or FTP server).

Any help would be appreciated.

If you wanted just all download all images referenced by img elements.

  1. Request the remote file with something like cURL.
  2. Use a DOM parser (such as DOMDocument) to get all img element.
  3. Iterate over the img elements and use cURL (or similar) to download each image (check the src attribute).

Not very easy, but not that hard:

Request the page using Curl, parse the HTML using DOMXpath and look for the src attributes of the images. Then download the images via Curl by adding the full http address to the image path/name.