Очень прошу помочь найти ошибку в коде!
Приведённый ниже код - кусок кода для парсинга фотографии со страниц Aliexpress, пример URL:
www.aliexpress.com/snapshot/6277050719.html?orderI...
Необходимо спарсить 2 картинки, находящиеся в этом участке исходного кода:
"imageURL": [
'http://i00.i.aliimg.com/kf/UT8Ug5xXe8XXXagOFbXf.jpg',
'http://i00.i.aliimg.com/kf/UT8ihaxXfhXXXagOFbXT.jpg'
]
Парсер не работает - прошу найти ошибку!
if(strpos($filecontents, 'aliexpress') !== false){
$filecontents = str_replace("www.aliexpress", "ru.aliexpress", $filecontents);
$fields = explode("||", $filecontents);
$link_in_array = explode("|", array_pop($fields));
$link = $link_in_array[1];
$page = file_get_contents($link);
$first_part = explode("var runParams = ", $page);
$second_part = explode("//]]>", $first_part[1]);
$array = $second_part[0];
$array = str_replace("'", "\"", $array);
$arr = json_decode($array);
$links_to_images = '';
foreach($arr->imageURL as $img)
{
$link = str_replace(" ","", $img);
$name_in_array = explode("/", $link);
$name = array_pop($name_in_array);
$file = file_get_contents($link);
$fp = fopen($_SERVER['DOCUMENT_ROOT'] . "/uploads/posts/" . date('Y-m') . "/" . $name, "w");
echo "<script>alert('" . $_SERVER['DOCUMENT_ROOT'] . "/uploads/posts/" . date('Y-m') . "/" . $name . "');</script>";
fwrite($fp, $file);
fclose($fp);
$links_to_images .= date('Y-m') . "/" . $name . "|||";
}
$files = substr($links_to_images, 0, -3);
$this_date = explode(" ", microtime());
$db->query( "INSERT INTO " . PREFIX . "_images (images, news_id, author, date) VALUES('{$files}', '{$row['id']}', '{$member_id['name']}', '{$this_date[1]}')" );
}
=====ЭТО ТОТ ЖЕ КОД, НО ЕГО ВРОДЕ БЫ ВЫ МОЖЕТЕ ЗАТЕСТИТЬ САМИ========================
$filecontents = "price|7,59||ekonomia|0||kachestvo|7||dostavka|30||link|http://www.aliexpress.com/snapshot/6445370171.html";
if(strpos($filecontents, 'aliexpress') !== false){
$filecontents = str_replace("www.aliexpress", "ru.aliexpress", $filecontents);
$fields = explode("||", $filecontents);
$link_in_array = explode("|", array_pop($fields));
$link = $link_in_array[1];
$page = file_get_contents($link);
$first_part = explode("var runParams = ", $page);
$second_part = explode("//]]>", $first_part[1]);
$array = $second_part[0];
$array = str_replace("'", "\"", $array);
$arr = json_decode($array);
$links_to_images = '';
foreach($arr->imageURL as $img)
{
$link = str_replace(" ","", $img);
$name_in_array = explode("/", $link);
$name = array_pop($name_in_array);
$file = file_get_contents($link);
$fp = fopen($_SERVER['DOCUMENT_ROOT'] . "/uploads/posts/" . date('Y-m') . "/" . $name, "w");
echo "<script>alert('" . $_SERVER['DOCUMENT_ROOT'] . "/uploads/posts/" . date('Y-m') . "/" . $name . "');</script>";
fwrite($fp, $file);
fclose($fp);
$links_to_images .= date('Y-m') . "/" . $name . "|||";
}
$files = substr($links_to_images, 0, -3);
print $files;
}