Exemplo n.º 1
0
function parse_product($page)
{
    // Если это страница товара, ишем описание
    if (preg_match_all('/<ul class="product-card__spec-list">(.*)<\\/ul>/uis', $page, $matches)) {
        // Описание товара
        $description = '<ul>' . reset($matches[1]) . '</ul>';
        $result = new stdClass();
        $result->description = $description;
        // Страница характеристик
        if (preg_match_all('/<li class="product-tabs__item" data-name="spec"><a href="(.*?)">/ui', $page, $matches)) {
            $options_url = 'http://' . DOMAIN . reset($matches[1]);
            $options_page = get_page($options_url);
            preg_match_all('/<dl class="product-spec-item"><dt class="product-spec-item__name"><span class="product-spec-item__name-inner">(.*?)<.*?<span class="product-spec-item__value-inner">(.*?)\\p{Z}?<\\/span><\\/dd><\\/dl>/uis', $options_page, $matches, PREG_SET_ORDER);
            $options = array();
            foreach ($matches as $m) {
                $option = new stdClass();
                $option->name = str_replace("\n", "", $m[1]);
                $option->value = str_replace("\n", "", $m[2]);
                $options[] = $option;
            }
            $result->options = $options;
        } else {
            return false;
        }
    } elseif (preg_match_all('/<a class="snippet-card__image link" href="(.*?)"><img/ui', $page, $matches)) {
        $product_url = 'http://' . DOMAIN . reset($matches[1]);
        $page = get_page($product_url);
        return parse_product($page);
    } else {
        return false;
    }
    return $result;
}
Exemplo n.º 2
0
function parse_product($page)
{
    // Если это страница товара, ишем описание
    if (preg_match_all('/<ul class="b-vlist b-vlist_type_mdash b-vlist_type_friendly">(.*?)/ui', $page, $matches)) {
        // Описание товара
        $description = '<ul>' . reset($matches[1]) . '</ul>';
        $result = new stdClass();
        $result->description = $description;
        // Страница характеристик
        if (preg_match_all('/<p class="b-model-friendly__title"><a href="(.*?)">/ui', $page, $matches)) {
            $options_url = 'http://' . DOMAIN . reset($matches[1]);
            $options_page = get_page($options_url);
            preg_match_all('/<th class="b-properties__label b-properties__label-title"><span>(.*?)<\\/span><\\/th><td class="b-properties__value">(.*?)<\\/td>/ui', $options_page, $matches, PREG_SET_ORDER);
            $options = array();
            foreach ($matches as $m) {
                $option = new stdClass();
                $option->name = $m[1];
                $option->value = $m[2];
                $options[] = $option;
            }
            $result->options = $options;
        } else {
            return false;
        }
    } elseif (preg_match_all('/<h3 class="b\\-offers__title"><a .*href="(\\/model\\.xml.*?)"/ui', $page, $matches)) {
        $product_url = 'http://' . DOMAIN . reset($matches[1]);
        $page = get_page($product_url);
        return parse_product($page);
    } else {
        return false;
    }
    return $result;
}