Revolveclothing.class.php
1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?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('请输入正确的商品地址!');
}
}
}