php_curl

作者: 啦啦咔咔啦 | 来源:发表于2019-07-08 17:06 被阅读0次
    <?php
    // 初始化curl
    $ch = curl_init();
    // 设置代理, 很多时候用来调试程序, 或者切换代理 ip 来采集一些防采集的网站
    // curl_setopt ($ch, CURLOPT_PROXY, '127.0.0.1:8888');
    // 设置要提交的 url
    curl_setopt ($ch, CURLOPT_URL, "https://www.baidu.com");
    // 是否显示头信息
    curl_setopt($ch, CURLOPT_HEADER, true);
    // 设置超时时间
    curl_setopt($ch, CURLOPT_TIMEOUT, 30);
    // CURLOPT_FOLLOWLOCATION 为 true, 则会跟着爬取重定向页面, 否则不会跟踪重定向页面 比如跟踪重定向
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    // 是否验证ssl证书, 在请求https时候, 设置 false 表示不验证
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    // 设置 ua 信息
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
    //  设置来路地址
    curl_setopt($ch, CURLOPT_REFEERER, "https://www.baidu.com");
    // 是否返回内容, 如果设为false的话, 表示直接输出到页面, 就不会在curl_exec执行的时候返回内容. 设置为true时候才返回
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
    // 执行curl请求
    curl_exec($ch);
    // 关闭curl连接
    curl_close($ch);
    

    相关文章

      网友评论

          本文标题:php_curl

          本文链接:https://www.haomeiwen.com/subject/dipohctx.html