Home > Backend Development > PHP Tutorial > php file_get_contents 转curl抓取淘宝商品属性 大神帮忙下,该怎么解决

php file_get_contents 转curl抓取淘宝商品属性 大神帮忙下,该怎么解决

WBOY
Release: 2016-06-13 12:22:54
Original
1078 people have browsed it

php file_get_contents 转curl抓取淘宝商品属性 大神帮忙下

本帖最后由 winniephp 于 2015-05-25 12:16:01 编辑 以下代码如何改为用 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 />}
Copy after login

------解决思路----------------------
这样吗?
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);
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template