首頁 >後端開發 >php教程 >利用curl抓取远程页面内容_PHP教程

利用curl抓取远程页面内容_PHP教程

WBOY
WBOY原創
2016-07-20 11:13:23860瀏覽

最基本的操作如下

<span $curlPost</span> = 'a=1&b=2';<span //</span><span 模拟POST数据</span>
<span $ch</span> =<span  curl_init();
curl_setopt(</span><span $ch</span>, CURLOPT_HTTPHEADER, <span array</span>('X-FORWARDED-FOR:0.0.0.0', 'CLIENT-IP:0.0.0.0'));  <span //</span><span 构造IP</span>
curl_setopt(<span $ch</span>, CURLOPT_REFERER, "http://www.baidu.com/");   <span //</span><span 构造来路 </span>
curl_setopt(<span $ch</span>,CURLOPT_URL, 'http://www.baidu.com'<span );<span //需要抓取的页面路径</span>
curl_setopt (</span><span $ch</span>, CURLOPT_RETURNTRANSFER, 1<span ); 
curl_setopt (</span><span $ch</span>, CURLOPT_TIMEOUT, 30<span );
curl_setopt(</span><span $ch</span>, CURLOPT_POSTFIELDS, <span $curlPost</span>);<span //</span><span post值</span>
        
<span $file_contents</span> = curl_exec(<span $ch</span>);<span //</span><span 抓取的内容放在变量中</span>
curl_close(<span $ch</span>)

 

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/440384.htmlTechArticle最基本的操作如下 = 'a=1b=2'; = , CURLOPT_HTTPHEADER, ('X-FORWARDED-FOR:0.0.0.0', 'CLIENT-IP:0.0.0.0')); curl_setopt( , CURLOPT_REFERER, "http://www.baidu.com/"); curl_setop...
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn