Image Scraping with Symfony’s DomCrawler

Posted by Unknown on Friday, March 28, 2014

A photographer friend of mine implored me to find and download images of picture frames from the internet. I eventually landed on a web page that had a number of them available for free but there was a problem: a link to download all the images together wasn’t present.


I didn’t want to go through the stress of downloading the images individually, so I wrote this PHP class to find, download and zip all images found on the website.



How the Class works


It searches a URL for images, downloads and saves the images into a folder, creates a ZIP archive of the folder and finally deletes the folder.


The class uses Symfony’s DomCrawler component to search for all image links found on the webpage and a custom zip function that creates the zip file. Credit to David Walsh for the zip function.



Coding the Class


The class consists of five private properties and eight public methods including the __construct magic method.


Continue reading %Image Scraping with Symfony’s DomCrawler%




more

{ 0 comments... » Image Scraping with Symfony’s DomCrawler read them below or add one }

Post a Comment

Popular Posts