Home > php教程 > php手册 > 利用curl抓取远程页面内容的示例代码

利用curl抓取远程页面内容的示例代码

WBOY
Release: 2016-06-06 20:28:24
Original
1418 people have browsed it

利用curl抓取远程页面内容的一个小示例,需要的朋友可以过来参考下

最基本的操作如下

复制代码 代码如下:


$curlPost = 'a=1&b=2';//模拟POST数据
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-FORWARDED-FOR:0.0.0.0', 'CLIENT-IP:0.0.0.0'));  //构造IP
curl_setopt($ch, CURLOPT_REFERER, "http://www.jb51.net/");   //构造来路
curl_setopt($ch,CURLOPT_URL, 'http://www.jb51.net');//需要抓取的页面路径
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);//post值

$file_contents = curl_exec($ch);//抓取的内容放在变量中
curl_close($ch)

,网站空间,美国空间,香港服务器
Related labels:
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