Home >Backend Development >PHP Tutorial >Using curl to grab remote page content_PHP tutorial

Using curl to grab remote page content_PHP tutorial

WBOY
WBOYOriginal
2016-07-20 11:13:23858browse

The most basic operations are as follows

<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.htmlTechArticleThe most basic operation is as follows = '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...
Statement:
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