Forever21.class.php 1.2 KB
<?php
/**
 * http://www.forever21.cn/(整站时间慢) 处理1.8-2.5s
 */
class Util_Product_Api_Forever21 extends Util_Product_Api
{
    public function getData($url)
    {
        $data = Util_Product_ApiConnect::get($url, array(CURLOPT_TIMEOUT=>10));
        if(!empty($data))
        {
            @phpQuery::newDocument($data);
            self::$product->name = pq('.items_name')->text();
            self::$product->price = pq('.price2')->text();
            $img = pq('#productImage')->attr('src');
            @preg_match_all('@/images/.+/.+-(\d){2}\.@is', $img, $out, PREG_SET_ORDER);
            self::$product->img = 'http://www.forever21.cn/'.$img;
            $id = sprintf("#spanbutton_%02d",$out[0][1]);
            $length = pq($id)->find('img')->length();
            for($i = 0; $i<$length; $i++)
            {
            	$img = pq($id)->find('img')->eq($i)->attr('src');
            	self::$product->imgs[] = 'http://www.forever21.cn/'.str_replace('button_', '', $img);
            }
          	self::$product->imgs = array_values(array_unique(self::$product->imgs)); 
        }
        else
        {
            throw new Util_Product_ApiException('请输入正确的商品地址!');
        }
    }
}