Shopbop.class.php 1.67 KB
<?php
/*
 * http://www.shopbop.com/ (时间:1s以上)
 * 例:
 *   http://cn.shopbop.com/fierra-back-dress-alice-olivia/vp/v=1/845524441960355.htm?folderID=2534374302025517&fm=other-shopbysize&colorId=21831-
 */
class Util_Product_Api_Shopbop extends Util_Product_Api
{
    private static $htmlUrl = 'http://cn.shopbop.com/actions/quickShopProductDetailPageAction.action?PRODUCT<>prd_id={id}';
    public function getData($url)
    {
        preg_match_all("@/v=[\d]/(.*)\.[htm|html]@", $url, $out, PREG_SET_ORDER);
        if(!empty($out))
        {
            $id = $out[0][1];
            $url = str_replace('{id}', $id, self::$htmlUrl);
            $data = Util_Product_ApiConnect::get($url);
            @phpQuery::newDocument($data);
            $doc = pq('#productDetailMainImage');
            self::$product->img = str_replace('201x396','', $doc->find('img')->attr('src'));
            self::$product->name = $doc->find('img')->attr('alt');
            $price = pq('.salePrice')->text();
            if(empty($price))
            {
                $price = pq('.priceBlock')->text();
            }
            self::$product->price = (float) $price;
            self::$product->unit = 'USD';
            $length = pq('#alternateImagesBody')->find('img')->length();
            for($i = 0; $i<$length; $i++)
            {
            	$img = pq('#alternateImagesBody')->find('img')->eq($i)->attr('src');
            	self::$product->imgs[] = str_replace('_44x87','', $img);
            }
            print_r(self::$product->imgs);
            exit();
        }
        else
        {
            throw new Util_Product_ApiException('请输入正确的商品地址!');
        }
        
    }
}