简体   繁体   中英

Download all images from a single webpage

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.

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.

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM