首页 > 后端开发 > php教程 > 利用curl抓取远程页面内容_PHP教程

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

WBOY
发布: 2016-07-20 11:13:23
原创
865 人浏览过

最基本的操作如下

<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...
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板