Mltd.class.php 1.12 KB
<?php
/**
 * http://www.mltd.com(国外) 时间很长 7-10s
 */
class Util_Product_Api_Mltd extends Util_Product_Api
{
    public function getData($url)
    {
        
        $data = Util_Product_ApiConnect::get($url, array(CURLOPT_TIMEOUT => 15));
        if(!empty($data))
        {
            @phpQuery::newDocument($data);
            self::$product->name = pq('#RightPanel')->find('.title')->eq(0)->text();
            self::$product->price = str_replace('$','', pq('#price')->text());
            self::$product->img =  pq('#mainImage')->attr('src');
            self::$product->unit = 'USD';
            $length = pq("#outerImages")->find("a")->length();
            for($i = 0; $i<$length; $i++)
            {
            	$script = pq("#outerImages")->find("a")->eq($i)->attr('onclick');
            	self::$product->imgs[] = preg_replace("@javascript:changeImage\('(.+)','(.+)'\);@",'\\2', $script);
            }
            self::$product->imgs = array_values(array_unique(self::$product->imgs));
        }
        else
        {
            throw new Util_Product_ApiException('请输入正确的商品地址!');
        }
    }

}