Vancl.class.php
1.14 KB
<?php
/**
* 网址:http://www.vancl.com/
* 凡客诚品
*/
class Util_Product_Api_Vancl extends Util_Product_Api
{
public function getData($url)
{
$url = preg_replace('/#(.*)/','', $url);
$data = Util_Product_ApiConnect::get($url);
if(!empty($data))
{
@phpQuery::newDocument($data);
//选择区域
$doc = pq(".danpinArea");
self::$product->name = iconv('utf-8','ISO-8859-1',$doc->find('h2')->text());
self::$product->price = sprintf('%0.2f', $doc->find('strong')->text());
self::$product->img = $doc->find('img')->attr('src');
$length = $doc->find('#imageMenu')->find('span')->length();
for($i = 0; $i<$length; $i++)
{
$img = $doc->find('#imageMenu')->find('span')->eq($i)->attr("name");
self::$product->imgs[] = str_replace('/small/','/mid/', $img);
}
self::$product->imgs = array_values(array_unique(self::$product->imgs));
}
else
{
throw new Util_Product_ApiException('请输入正确的商品地址!');
}
}
}