以下代碼如何改為用 curl來抓取呢?並且以商品的IID儲存
function get_shuxing($type,$iid){if($type=='tmall'){$text=file_get_contents("http://detail.tmall.com/item.htm?id=$iid");preg_match('||isU',$text, $match);}elseif ($type=='taobao'){$text=file_get_contents("http://item.taobao.com/item.htm?id=$iid");preg_match('|
|isU',$text, $match);}$match=$match[0];$match = iconv('gbk', 'utf-8', $match);echo $match;}
回複討論(解決方案)
有哪位大神幫忙呢》
你不給測試資料怎麼弄,再怎麼也得給個$iid吧...
你不給測試資料怎麼弄,再怎麼也得給個$iid吧...
http://detail.tmall.com/item.htm?id=13317551791
可以嗎!就是擷取商品的產品參數
$html=file_get_contents('http://detail.tmall.com/item.htm?id=13317551791');include 'simple_html_dom.php';//網上下一個 $dom=new simple_html_dom();// $html utf8才可以$dom->load($html);$names=$dom->find('select[id=js]');$res=array();$lis=$dom->find('ul[id=J_AttrUL] li');foreach($lis as $k=>$li){ $temp=$li->text();list($key,$value)=explode(':',$temp);$data[$key]=$value;}echo "";print_r($data);echo "
";/*Array( [上市年份季節] => 2015年夏季 [褲長] => 長褲 [貨號] => Y306 [顏色] => Y139藍色 Y118藍色偏小一碼 Y139複古藍 Y306黑藍 深色Y306/藍色 Y306淺藍色 YN8601藍色 Y007懷舊藍 [尺碼] => 40 38 36 34 33 32 31 30 29 28 [牛仔面料] => 常規牛仔布 [工藝處理] => 壓皺 水洗 複古 商務 個性 潮牌 休閑 nzk 修身 漂白 貓須 破洞 雪花洗 手擦 磨邊 刮爛 電磨 針縫 噴砂 赤耳 馬騮 鑲邊 無工藝 紮花 刺繡 紮染 [品牌] => YYK [款式細節] => 立體剪裁 [上市時間] => 2013年 [適用季節] => 夏季 [適用對象] => 大碼 [材質] => 棉滌 [彈力] => 無彈 [腰型] => 中腰 [褲腳口款式] => 直腳 [褲門襟] => 拉鏈 [洗水工藝] => 水洗 石洗/石磨 砂洗 石漂洗 漂染 碧紋洗 吊染 雪花洗 酵素洗 化學洗 [厚薄] => 薄款 [款式版型] => 合體直筒 [基礎風格] => 時尚都市 [細分風格] => 日系複古)*/
$html=file_get_contents('http://detail.tmall.com/item.htm?id=13317551791');include 'simple_html_dom.php';//網上下一個 $dom=new simple_html_dom();// $html utf8才可以$dom->load($html);$names=$dom->find('select[id=js]');$res=array();$lis=$dom->find('ul[id=J_AttrUL] li');foreach($lis as $k=>$li){ $temp=$li->text();list($key,$value)=explode(':',$temp);$data[$key]=$value;}echo "";print_r($data);echo "
";/*Array( [上市年份季節] => 2015年夏季 [褲長] => 長褲 [貨號] => Y306 [顏色] => Y139藍色 Y118藍色偏小一碼 Y139複古藍 Y306黑藍 深色Y306/藍色 Y306淺藍色 YN8601藍色 Y007懷舊藍 [尺碼] => 40 38 36 34 33 32 31 30 29 28 [牛仔面料] => 常規牛仔布 [工藝處理] => 壓皺 水洗 複古 商務 個性 潮牌 休閑 nzk 修身 漂白 貓須 破洞 雪花洗 手擦 磨邊 刮爛 電磨 針縫 噴砂 赤耳 馬騮 鑲邊 無工藝 紮花 刺繡 紮染 [品牌] => YYK [款式細節] => 立體剪裁 [上市時間] => 2013年 [適用季節] => 夏季 [適用對象] => 大碼 [材質] => 棉滌 [彈力] => 無彈 [腰型] => 中腰 [褲腳口款式] => 直腳 [褲門襟] => 拉鏈 [洗水工藝] => 水洗 石洗/石磨 砂洗 石漂洗 漂染 碧紋洗 吊染 雪花洗 酵素洗 化學洗 [厚薄] => 薄款 [款式版型] => 合體直筒 [基礎風格] => 時尚都市 [細分風格] => 日系複古)*/
雖然是可以,但是不是我想要的,謝謝啦
這些不是產品參數?資料都取出來了,至於怎麼用,就看你自己處理,我又不是知道你要什麼樣的資料格式,一維,二維?索引值對?
不要用正則,我記得抓這些屬性有http要求方法的,你抓個包就知道了
這樣嗎?
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('||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('|
|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);
這樣嗎?
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('||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('|
|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);
就是想改成這樣的,但是tmall的參數卻無法擷取到,改回我自己的又正常,奇怪了
這樣嗎?
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('||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('|
|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);
就是想改成這樣的,但是tmall的參數卻無法擷取到,改回我自己的又正常,奇怪了
302 Found302 Found
The requested resource resides temporarily under a different URI.
Powered by Tengine
tmall 返回302了