Stylefile.class.php 1.09 KB
<?php
/**
 *  http://www.stylefile.com(时间有点长,2-5s)
 *
 */
class Util_Product_Api_Stylefile extends Util_Product_Api
{
    public function getData($url)
    {
        $data = Util_Product_ApiConnect::get($url);
        if(!empty($data))
        {
            @phpQuery::newDocument($data);
            $doc = pq('#DetailsOptions');
            self::$product->name = $doc->find('h2')->text();
            self::$product->price = (float) $doc->find('.detailsPrice')->text();
            self::$product->img = pq('#DetailsStage')->find('img')->attr('src');
            self::$product->unit = 'EUR';
            $length = pq('#DetailsGallery')->find('img')->length();
            for($i = 0; $i<$length; $i++)
            {
            	$img = pq('#DetailsGallery')->find('img')->eq($i)->attr('src');
            	self::$product->imgs[] = str_replace('-thumb','', $img);
            }
            self::$product->imgs = array_values(array_unique(self::$product->imgs));
        }
        else
        {
            throw new Util_Product_ApiException('请输入正确的商品地址!');
        }
    }
}