Home > php教程 > php手册 > 利用curl抓取远程页面内容

利用curl抓取远程页面内容

WBOY
Release: 2016-06-13 11:29:13
Original
933 people have browsed it

最基本的操作如下

<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>)
Copy after login

 

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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template