Xipin.class.php
992 Bytes
<?php
/**
* http://www.xipin.me
*/
class Util_Product_Api_Xipin extends Util_Product_Api
{
public function getData($url)
{
$data = Util_Product_ApiConnect::get($url);
@phpQuery::newDocument($data);
if(!empty($data))
{
self::$product->name = pq('.productName')->text();
self::$product->img = pq('.cm-image-wrap')->find('img')->attr('src');
self::$product->price = pq('.price-num')->text();
$length = pq('.jcarousel-skin')->find('img')->length();
for($i = 0; $i<$length; $i++)
{
$img = pq('.jcarousel-skin')->find('img')->eq($i)->attr("src");
self::$product->imgs[] = str_replace('/30/30/', '/478/478/',$img);
}
self::$product->imgs = array_values(array_unique(self::$product->imgs));
}
else
{
throw new Util_Product_ApiException('请输入正确的商品地址!');
}
}
}