Shopbop.class.php
1.63 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
40
41
42
<?php
/*
* http://www.shopbop.com/ (时间:1s以上)
* 例:
* http://cn.shopbop.com/fierra-back-dress-alice-olivia/vp/v=1/845524441960355.htm?folderID=2534374302025517&fm=other-shopbysize&colorId=21831-
*/
class Util_Product_Api_Shopbop extends Util_Product_Api
{
private static $htmlUrl = 'http://cn.shopbop.com/actions/quickShopProductDetailPageAction.action?PRODUCT<>prd_id={id}';
public function getData($url)
{
preg_match_all("@/v=[\d]/(.*)\.[htm|html]@", $url, $out, PREG_SET_ORDER);
if(!empty($out))
{
$id = $out[0][1];
$url = str_replace('{id}', $id, self::$htmlUrl);
$data = Util_Product_ApiConnect::get($url);
@phpQuery::newDocument($data);
$doc = pq('#productDetailMainImage');
self::$product->img = str_replace('201x396','', $doc->find('img')->attr('src'));
self::$product->name = $doc->find('img')->attr('alt');
$price = pq('.salePrice')->text();
if(empty($price))
{
$price = pq('.priceBlock')->text();
}
self::$product->price = (float) $price;
self::$product->unit = 'USD';
$length = pq('#alternateImagesBody')->find('img')->length();
for($i = 0; $i<$length; $i++)
{
$img = pq('#alternateImagesBody')->find('img')->eq($i)->attr('src');
self::$product->imgs[] = preg_replace('/_[0-9]{2}x[0-9]{2}/','_336x596',$img);
}
}
else
{
throw new Util_Product_ApiException('请输入正确的商品地址!');
}
}
}