Hm.class.php 1.25 KB
<?php
/**
 * http://www.hm.com/cn/en/product/07109?article=07109-C#cm_vc=SIMILAR_TO_PD
 *
 */
class Util_Product_Api_Hm extends Util_Product_Api
{
    public function getData($url)
    {
        $data = Util_Product_ApiConnect::get($url);
        if(!empty($data))
        {
            @phpQuery::newDocument($data);
            $content = pq('h1')->html();
            preg_match_all('@<span (.*)</span>@isU', $content, $out, PREG_SET_ORDER);
            $price = trim(strip_tags($out[0][0]));
            self::$product->name = trim(strip_tags(preg_replace('@<span (.*)</span>@isU','', $content)));
            self::$product->price =  str_ireplace('RMB','', $price);
            self::$product->img = str_replace(' ','%20','http:'.pq('#product-image')->attr('src'));
            $length = pq('#product-thumbs')->find('a')->length();
            for($i= 0; $i<$length; $i++)
            {
            	$img =pq('#product-thumbs')->find('a')->eq($i)->attr('href');
            	self::$product->imgs[] = str_replace(' ','%20','http:'.$img);
            }
            self::$product->imgs = array_values(array_unique(self::$product->imgs));
        }
        else
        {
            throw new Util_Product_ApiException('请输入正确的商品地址!');
        }
    }
}