PHP Download images` links from ebay listings to csv file

I am trying to download some images urls in a csv file. I am using the MPNs from an input csv file. I open each listing and search for image link, my array of links $itemInfo is empty. Here is my code:

$fRead = fopen("JeepToysEbayIsr.csv", "r");
fgetcsv($fRead);
while ($line = fgetcsv($fRead)) {
$ids[] = $line[0];
}
fclose($fRead);
// print_r($ids);die();
$fp = fopen("AllImages.csv", "w");
fputcsv($fp, array("ebayId", "variationName", "images"));

foreach ($ids as $key => $id) {
// $id = '390573574298';
$url = 'https://www.ebay.co.uk/sch/i.html?_from=R40&_trksid=p2380057.m570.l1313.TR0.TRC0.H0.X3342827.TRS0&_sacat=0&_nkw='.$id;
$data = get_web_page($url);


if(preg_match("/id=\"vi_main_img_fs\"(.*?)gspr flm-btn nxt/s", $data, $imageDiv)){
 preg_match_all("/<img(.*?)\/>/", $imageDiv[1], $imageTags);
}

$itemInfo = array();
$itemInfo['id'] = $id;
if (isset($imageTags[1])) {

foreach ($imageTags[1] as $img) {
    preg_match("/src=\"(.*?)\"/", $img, $url);
    $itemInfo[] = str_replace("l64", "l1600", $url[1]);
}
}
else{
  if (preg_match("/id=\"mainImgHldr\"(.*?)<\/div/s", $data, $main) !== false) {
      if ($main) {
    preg_match("/icImg.*src=\"(.*?)\"/", $main[1], $matches);
    $itemInfo[] = $matches[1];
    //print_r($itemInfo);
      }
  }
}
unset($imageTags);
}   
fputcsv($fp, $itemInfo);

fclose($fp);

I think in the match section something is not right so I am wondering what has to be changed?

Why do you want to change something? But anyway i don’t see how somebody should do something without a sample input of your CSV.

Here is what I use: HON-15-031/30,HYU-15-025/40- with these I open the url and search there for an image. Then I want to get the image link and put it in a csv file.

But that doesn’t look like a valid ID, i get an error when appending it to the URL and opening it in a browser.

It is actually an MPN and with it I open each listing and search for info.

Still http://www.ebay.com/itm/HON-15-031/30 does not give anything product related.

This is because my search pattern was wrong, I changed it and now the link is opened

Sponsor our Newsletter | Privacy Policy | Terms of Service