Revolveclothing.class.php 1.17 KB
<?php
/**
 * http://www.revolveclothing.com/
 *
 */
class Util_Product_Api_Revolveclothing extends Util_Product_Api
{
	public function getData($url)
	{
		$data = Util_Product_ApiConnect::get(urldecode($url), array(CURLOPT_TIMEOUT => 10));
		if(!empty($data))
		{
			@phpQuery::newDocument($data);
			$doc = pq('.detail_shop');
			self::$product->name =  $doc->find('h1')->text();
			$price =  str_replace(',','',$doc->find('.price')->text());
			$pos = strpos($price, substr(preg_replace('/\D+/','', $price), 0,1));
			if(empty($pos))
			{
				$price =  str_replace(',','',$doc->find('.saleprice')->text());
				$pos = strpos($price, substr(preg_replace('/\D+/','', $price), 0,1));
			}
			self::$product->price = trim(substr($price, $pos));
			$doc = pq('.detail_img_thumb')->find('#thumbnaildata')->find('ul');
			$length = $doc->find('li')->length();
			$imgs = array();
			for($i=0; $i<$length; $i++)
			{
				$imgs[] = str_replace('/p/n/dt/','/p/n/d/',$doc->find('img')->eq($i)->attr('src'));
			}
			self::$product->imgs = array_values(array_unique($imgs));
			self::$product->img = $imgs[0];
		}
		else
		{
			throw new Util_Product_ApiException('请输入正确的商品地址!');
		}
	}
}