Today we are going to create a simple Pinterest images parser. It will search for pins according to some keywords and then save them to disk. So, let’s start. For interacting with Pinterest in PHP we will Pinterest Bot for PHP.
For example, we need to parse all cats images that we can find. Ok. First of all, we need to find pins related to cats keyword:
In the last line, we have an array of one hundred search results by cats keyword. Nice, now we need to save them on disk in the image folder. At first, let’s dump one of these array elements.
Each item in $pins array also is a huge array of different pin data:
For our needs, we pay attention only to images subarray. It has URLs of different image sizes. We are going to use original image size, so to save it we need to get its URL from $pin['images']['orig']['url']. And then save it on disk like this:
We use basename() function to get file name and then file_put_contents() to store the original pin image on our disk. So, here is the final version:
We loop through search results and save every pin in images folder. That’s it! Very simple.
You can find examples from this article on GitHub.