php抓取商品信息,tmall天猫获取所有商品信息的采集规则(php json)

发现tmall页面的静态内容采用了cdn分片,页面中变化的内容,都放到了cdn里,所有商品的信息都可以在JSON中获取,也许是方便在更新商品的时候,不用更新商品详情页的静态文件吧。

下面的代码可以读取商品的详细信息,并对信息做了简单处理,方便火车采集器采集调用

[php]

$url = 'http://tdecorate.tbcdn.cn/dc/fetchDc.htm?pid=72854835&sellerId=130974249';

$url = 'http://tdecorate.tbcdn.cn/dc/fetchDc.htm?pid=640211846&sellerId=737591379';

$html = @file_get_contents($url);

echo tidy($html);

function tidy($html)

{

//过滤js中的换行符

$html = str_replace(array('\r', '\n', '\t', 'http://a.tbcdn.cn/kissy/1.0.0/build/imglazyload/spaceball.gif', 'data-ks-lazyload'),

array("\r", "\n", "\t", '', 'src'),

$html);

//Js unicode解码

$html = unicode_decode($html);

//去掉反斜杠转议符

$html = stripslashes($html);

//过滤特殊样式

$html = str_replace(array(' src="http://a.tbcdn.cn/kissy/1.0.0/build/imglazyload/spaceball.gif"', 'data-ks-lazyload'),

array('', 'src'),

$html);

//匹配出内容

$html = get_desc($html);

return trim($html);

}

function unicode_decode($string)

{

$string = preg_replace_callback('#\\\u([0-9a-f]{4})#ism', create_function('$matches', 'return mb_convert_encoding(pack("H*", $matches[1]), "UTF-8", "UCS-2BE");'), $string);

return $string;

}

function get_desc($html)

{

preg_match('@"DcTopRight"[\s\S]*?"html":"([\s\S]*?)\s+\},@is', $html, $match);

return $match[1];

}

[/php]

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值