当前位置:主页 > 软件编程 > PHP代码 >

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

时间:2021-05-17 08:40:26 | 栏目:PHP代码 | 点击:

最基本的操作如下
复制代码 代码如下:

$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, "https://www.jb51.net/");   //构造来路
curl_setopt($ch,CURLOPT_URL, 'https://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)

您可能感兴趣的文章:

相关文章