Zara.class.php
1.54 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
43
44
45
<?php
/**
* http://www.zara.cn
*/
class Util_Product_Api_Zara extends Util_Product_Api
{
public function getData($url)
{
phpQuery::$defaultCharset = 'gb2312';
$data = Util_Product_ApiConnect::get(urldecode($url));
if(!empty($data))
{
@phpQuery::newDocument($data);
$prodInfoDoc = pq("#product");
self::$product->name = trim($prodInfoDoc->find("h1")->text());
$price = $prodInfoDoc->find('.sale')->attr("data-price");
if(empty($price))
{
$price = $prodInfoDoc->find('.price span')->attr("data-price");
}
self::$product->price = trim(str_replace(array('¥',','), '', $price));
self::$product->img = pq('#bigImage')->eq(0)->attr("data-src");
if (strpos(self::$product->img, 'http://') !== 0)
{
self::$product->img = 'http:'.self::$product->img;
}
$length = $prodInfoDoc->find('.image-wrap')->length();
for($i = 0; $i<$length; $i++)
{
$img = $prodInfoDoc->find('.image-wrap')->eq($i)->find('img')->attr('data-src');
if (strpos($img, 'http://') !== 0)
{
$img = 'http:'.$img;
}
self::$product->imgs[] = $img;
}
self::$product->imgs = array_values(array_unique(self::$product->imgs));
}
else
{
throw new Util_Product_ApiException('请输入正确的商品地址!');
}
}
}