Asos.class.php 1.16 KB
<?php
/**
 * 
 * http://www.asos.com(国外的)速度有点慢1.4-4s,有时取不到数据
 *
 */
class Util_Product_Api_Asos extends Util_Product_Api
{
    public function getData($url)
    {
        $data = Util_Product_ApiConnect::get($url.'&r=2', array(
                        CURLOPT_ENCODING => 'gzip', CURLOPT_TIMEOUT_MS => 7000,
                        CURLOPT_HTTPHEADER=> array
                        (
                            'Accept-Charset: GB-2312,utf-8;q=0.7,*;q=0.7', 
                            'Accept-Language: zh-CN,zh;q=0.5',
                        )
                ));
        if(!empty($data))
        {
            @phpQuery::newDocument($data); 
            self::$product->name = pq('#ctl00_ContentMainPage_ctlBreadCrumbs_lblBreadCrumbs')->text();
            self::$product->price = str_replace('£','', pq('#ctl00_ContentMainPage_ctlSeparateProduct_lblProductPrice')->text());
            self::$product->img = pq('#ctl00_ContentMainPage_imgMainImage')->attr('src');
            self::$product->unit = 'GBP';
        }
        else
        {
            throw new Util_Product_ApiException('请输入正确的商品地址!');
        }
    }

}