Gap.class.php
1.19 KB
<?php
/**
* http://www.gap.cn/
*
*/
class Util_Product_Api_Gap extends Util_Product_Api
{
public function getData($url)
{
$data = Util_Product_ApiConnect::get($url);
preg_match_all('@.+/product/([0-9]{1,20})@', $url, $out, PREG_SET_ORDER);
$id = intval($out[0][1]);
if(!empty($data) && !empty($id))
{
@phpQuery::newDocument($data);
$doc = pq("#rightmain");
self::$product->name = $doc->find('h1')->text();
self::$product->img = $doc->find('img')->attr('src');
self::$product->color = trim($doc->find('#showColor')->text());
self::$product->price = trim($doc->find('#price_'.($id+1))->attr('rel'));
$length = pq(".more-views")->find("img")->length();
for($i = 0;$i<$length; $i++)
{
$img = str_replace('/45x60/','/', pq(".more-views")->find("img")->eq($i)->attr("src"));
self::$product->imgs[] = $img;
}
self::$product->imgs = array_values(array_unique(self::$product->imgs));
}
else
{
throw new Util_Product_ApiException('请输入正确的商品地址!');
}
}
}