php file_get_contents 转curl抓取淘宝商品属性 大神帮忙下
本帖最后由 winniephp 于 2015-05-25 12:16:01 编辑
(本文来)源gaodaimacom搞#^代%!码&网(
搞gaodaima代码
以下代码如何改为用 curl来抓取呢?并且以商品的IID保存
<br />function get_shuxing($type,$iid){<br />if($type=='tmall'){<br />$text=file_get_contents("http://detail.tmall.com/item.htm?id=$iid");<br />preg_match('|<ul id="J_AttrUL">(.*)</ul>|isU',$text, $match);<br />}elseif ($type=='taobao'){<br />$text=file_get_contents("http://item.taobao.com/item.htm?id=$iid");<br />preg_match('|<ul class="attributes-list">(.*)</ul>|isU',$text, $match);<br />}<br />$match=$match[0];<br />$match = iconv('gbk', 'utf-8', $match);<br />echo $match;<br />}
——解决思路———————-
这样吗?
function get_shuxing($type,$iid){<br /> if($type=='tmall'){<br /> //$text=file_get_contents("http://detail.tmall.com/item.htm?id=$iid");<br /> $text=use_curl("http://detail.tmall.com/item.htm?id=$iid");<br /> preg_match('<br><font color='#FF8000'>------解决思路----------------------</font><br><ul id="J_AttrUL">(.*)</ul><br><font color='#FF8000'>------解决思路----------------------</font><br>isU',$text, $match);<br /> }elseif ($type=='taobao'){<br /> //$text=file_get_contents("http://item.taobao.com/item.htm?id=$iid");<br /> $text=use_curl("http://item.taobao.com/item.htm?id=$iid");<br /> preg_match('<br><font color='#FF8000'>------解决思路----------------------</font><br><ul class="attributes-list">(.*)</ul><br><font color='#FF8000'>------解决思路----------------------</font><br>isU',$text, $match);<br /> }<br /> $match=$match[0];<br /> $match = iconv('gbk', 'utf-8', $match);<br /> echo $match;<br />}<br />function use_curl($url){<br /> $ch = curl_init($url);<br /> curl_setopt($ch, CURLOPT_HEADER, 0);<br /> curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);<br /> $output = curl_exec($ch);<br /> curl_close($ch);<br /> return $output;<br />}<br />get_shuxing('taobao',45098460735);
搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:php file_get_contents 转curl抓取淘宝商品属性 大神帮忙下,该怎么解决
转载请注明原文链接:php file_get_contents 转curl抓取淘宝商品属性 大神帮忙下,该怎么解决
