PHP file_get_html高级选项 - Web抓取

I created this function for my wordpress site to grab the featured image from the suppliers webpage - where the featured image class is "device-image" it works fine but there is a problem.

On many of my target $url's there are multiple colours of the product im downloading images for (im using wp-all import with this function) and each of my posts titles are like 'product 1 green', 'product 1 red', 'product 2 green', 'product 2 red' etc.

So I need to enhance this function to download the correct color image depending on my product title - the target url uses some kind of swatch to select a colour which then changes the device-image colour.

The problem is my function doesn't handle this so I need to make the function below switch through the swatches to get the correct device-image(colour) depending on my product title e.g. product 1 green. Im unsure of how I should proceed..

Example of target url: https://www.o2.co.uk/shop/phones/samsung/galaxy-s6-edge/#colour=sapphire-black&memory=128gb&contractType=paymonthly

The function below simply strips the src from the html of the device-image class. Also the URL seems to have #colour selector inside of it but I have no way of selecting it as the colours on there own are not present in my datafeed.

I need to sift through all colours and find the right one which most matches my title any ideas? My problem is I've ended up with the correct images but incorrect colors.


//function to grab device image from supplier for wp all import featured images requires simple_html_dom.php

function gimage($url) {

include('library/simple_html_dom.php');

$html = file_get_html($url);

foreach($html->find('img.device-image') as $e)
   echo 'https://www.o2.co.uk'.$e->src;
}   

//recall function

gimage("INSERT_PAGE_URL");