以下代码如何改为用 curl来抓取呢?并且以商品的IID保存
function get_shuxing($type,$iid){
if($type=='tmall'){
$text=file_get_contents("http://detail.tmall.com/item.htm?id=$iid");
preg_match('|<ul id="J_AttrUL">(.*)</ul>|isU',$text, $match);
}elseif ($type=='taobao'){
$text=file_get_contents("http://item.taobao.com/item.htm?id=$iid");
preg_match('|<ul class="attributes-list">(.*)</ul>|isU',$text, $match);
}
$match=$match[0];
$match = iconv('gbk', 'utf-8', $match);
echo $match;
}
------解决思路----------------------
这样吗?
function get_shuxing($type,$iid){
if($type=='tmall'){
//$text=file_get_contents("http://detail.tmall.com/item.htm?id=$iid");
$text=use_curl("http://detail.tmall.com/item.htm?id=$iid");
preg_match('
------解决思路----------------------
<ul id="J_AttrUL">(.*)</ul>
------解决思路----------------------
isU',$text, $match);
}elseif ($type=='taobao'){
//$text=file_get_contents("http://item.taobao.com/item.htm?id=$iid");
$text=use_curl("http://item.taobao.com/item.htm?id=$iid");
preg_match('
------解决思路----------------------
<ul class="attributes-list">(.*)</ul>
------解决思路----------------------
isU',$text, $match);
}
$match=$match[0];
$match = iconv('gbk', 'utf-8', $match);
echo $match;
}
function use_curl($url){
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
get_shuxing('taobao',45098460735);