利用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)
,网站空间,美国空间,香港服务器