前段时间一个朋友需要些一个采集淘宝评论的代码来为自己的cms做原创优化,存在2个问题,一个是编码,一个是采集接口。直接上我写的代码吧;
function getword(){
// 淘宝评论的js,itemId和sellerId在采用的天猫产品页面看源代码能找到,spuId不用管
$url ='https://rate.tmall.com/list_detail_rate.htm?itemId=42154201960&spuId=1714128138&sellerId=1714128138&order=1';
$res = file_get_contents($url);
// 匹配评论部分
preg_match_all("/Content\":\"((.|\n)*?)\"/",$res, $match);
$wt = array();
$arr = $match[1];
// 去除空评论
foreach ($arr as $v) {
if($v != ''){
// 转化成utf-8编码
$wt[] = iconv("GBK","UTF-8", $v);
}
}
return $wt;
}
</pre><pre>
不明白的加qq:79442126