php curl 抓去远程页面内容

时间:2023-03-09 01:13:20
php curl 抓去远程页面内容

<?php
/**
* php curl抓取远程网页内容
* edit by www.jbxue.com
*/
$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.jbxue.com/"); //构造来路
curl_setopt($ch,CURLOPT_URL, 'http://www.jbxue.com');//需要抓取的页面路径
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)
?>