怎么用PHP抓取网站HTML
连接地址
http://detail.tmall.com/item.htm?spm=a230r.1.0.0.MlI5e4&id=40364502055&ad_id=&am_id=&cm_id=140105335569ed55e27b&pm_id=&abbucket=12
抓取上面连接的 HTML
2本文来源gao!daima.com搞$代!码网
搞代gaodaima码 用file_get_contents() 测试没成功 怎么回事啊?
——解决思路———————-
file_get_contents() 成功了呀
——解决思路———————-
<br /><?php <br /> $url="http://detail.tmall.com/item.htm?spm=a230r.1.0.0.MlI5e4&id=40364502055&ad_id=&am_id=&cm_id=140105335569ed55e27b&pm_id";<br /> $content = getcurl($url);<br /> echo $content;<br /><br /> <br /> function getcurl($url){<br /> $ch = curl_init(); <br /> curl_setopt($ch, CURLOPT_URL, $url);<br /> curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);<br /> curl_setopt($ch, CURLOPT_FOLLOWLOCATION,true);<br /> curl_setopt($ch, CURLOPT_MAXREDIRS,20);<br /> $file_contents = curl_exec($ch);<br /> return $file_contents;<br /> curl_close($ch);<br /> }<br />?><br />
其中curl_setopt($ch, CURLOPT_FOLLOWLOCATION,true);设置比较重要,可以用来跟随天猫的重定向页面。