Zozo.class.php
1.05 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
<?php
/**
* http://zozo.jp/
*
*/
class Util_Product_Api_Zozo extends Util_Product_Api
{
public function getData($url)
{
$data = '';
$i = 0;
while(empty($data) && $i<5)
{
$data = Util_Product_ApiConnect::get(urldecode($url), array(CURLOPT_TIMEOUT => 10));
$i++;
}
phpQuery::$defaultCharset = 'Shift_JIS';
if(!empty($data))
{
@phpQuery::newDocument($data);
$doc = pq('.infoBlock');
self::$product->name = $doc->find('h1')->text();
self::$product->price = trim(str_replace(array(',','¥'), '', $doc->find('.price')->text()));
self::$product->unit = 'JPY';
$picDoc = pq('#photoThimb');
$imgs = array();
$length = $picDoc->find('li')->length();
if($length>10)
{
$length = 10;
}
for($i = 0;$i<$length; $i++)
{
$imgs[] = str_replace('_35','_500', $picDoc->find('#goodsdiv_'.$i)->find('img')->attr('src'));
}
self::$product->imgs = array_values(array_unique($imgs));
self::$product->img = $imgs[0];
}
else
{
throw new Util_Product_ApiException('请输入正确的商品地址!');
}
}
}