Zara.class.php 1.54 KB
<?php
/**
 * http://www.zara.cn
 */
class Util_Product_Api_Zara extends Util_Product_Api
{
    public function getData($url)
    {
        phpQuery::$defaultCharset = 'gb2312';
        $data = Util_Product_ApiConnect::get(urldecode($url));
        if(!empty($data))
        {
            @phpQuery::newDocument($data);
            $prodInfoDoc = pq("#product");
            self::$product->name = trim($prodInfoDoc->find("h1")->text());
            $price = $prodInfoDoc->find('.sale')->attr("data-price");
        
            if(empty($price))
            {
            	$price = $prodInfoDoc->find('.price span')->attr("data-price");
            }
            self::$product->price = trim(str_replace(array('¥',','), '', $price));
            self::$product->img = pq('#bigImage')->eq(0)->attr("data-src");
            if (strpos(self::$product->img, 'http://') !== 0)
            {
            	self::$product->img = 'http:'.self::$product->img;
            }
            $length = $prodInfoDoc->find('.image-wrap')->length();
            for($i = 0; $i<$length; $i++)
            {
            	$img = $prodInfoDoc->find('.image-wrap')->eq($i)->find('img')->attr('data-src');
            	if (strpos($img, 'http://') !== 0)
            	{
            		$img = 'http:'.$img;
            	}
            	self::$product->imgs[] = $img;
            }
            self::$product->imgs = array_values(array_unique(self::$product->imgs));
        }
        else
        {
            throw new Util_Product_ApiException('请输入正确的商品地址!');
        }
    }
}