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?