Yoox.class.php
1.11 KB
<?php
/**
* http://www.yoox.cn
*/
class Util_Product_Api_Yoox extends Util_Product_Api
{
public function getData($url)
{
phpQuery::$defaultCharset = 'gb2312';
$data = Util_Product_ApiConnect::get($url);
if(!empty($data))
{
@phpQuery::newDocument($data);
$doc = pq('#itemHeader');
self::$product->name = $doc->find("h2")->text().' '.$doc->find('span[itemprop="name"]')->text();
self::$product->price = str_replace(array('¥',','),'', $doc->find('span[itemprop="price"]')->text());
self::$product->img = pq('#mainImage')->attr('src');
$length = pq('#itemThumbs')->find('img')->length();
for($i = 0; $i<$length; $i++)
{
$img = pq('#itemThumbs')->find('img')->eq($i)->attr('src');
self::$product->imgs[] = str_replace('_9_','_12_', $img);
}
self::$product->imgs = array_values(array_unique(self::$product->imgs));
}
else
{
throw new Util_Product_ApiException('请输入正确的商品地址!');
}
}
}