zoukankan      html  css  js  c++  java
  • PHP curl 采集内容之规则 1

    <?php
    header("Content-type:text/html; charset=utf-8");
    $pattern = '/xxx(.*)yyyy/isU'; //i 不区分大小,s表示点号匹配换行 U 防贪婪匹配
    $url = "";
    $ch = curl_init($url);
    $options = array(
                CURLOPT_RETURNTRANSFER => true,         // return web page 以字符流返回不输出浏览器
             // CURLOPT_HEADER         => false,        // don't return headers
             // CURLOPT_FOLLOWLOCATION => true,         // follow redirects
             // CURLOPT_ENCODING       => "",           // handle all encodings
                //CURLOPT_USERAGENT      => "spider",     // who am i
             // CURLOPT_AUTOREFERER    => true,         // set referer on redirect
                CURLOPT_CONNECTTIMEOUT => 120,          // timeout on connect
                CURLOPT_TIMEOUT        => 120,          // timeout on response
             // CURLOPT_MAXREDIRS      => 10,           // stop after 10 redirects
             // CURLOPT_POST            => 1,            // i am sending post data
                //   CURLOPT_POSTFIELDS     => $curl_data,    // this are my post vars
            //  CURLOPT_SSL_VERIFYHOST => 0,            // don't verify ssl
            //  CURLOPT_SSL_VERIFYPEER => false,        //
             // CURLOPT_VERBOSE        => 1                //
        );
            curl_setopt_array($ch, $options);
            $texts = curl_exec($ch);
            if(preg_match($pattern, $texts, $arr)){
            //$arr[0] 包含正则中的字符
            // $arr[1] 不包含正则中的字符
            }

            if(preg_match_all($pattern, $texts, $arr)){
                //返回一个二维数组,包含多次匹配数据

            }
            curl_close($ch);
    ?>
  • 相关阅读:
    【弹道】Cocos 跟踪导弹
    腾讯云短信测试 (云短信、短信验证码)
    【组件】战斗力滚动数字
    Navicat访问远程服务器数据库
    解决Python读取SQL Server中文乱码问题
    【前端】GIS及JS题目
    【Postgres】空间计算
    PYTHONPATH在vscode和pycahrm的区别?为什么有的代码在vscode导入报错,pycahrm正常?精通PYTHONPATH作用真的很重要
    python 快速万能同步转异步语法
    fastjson序列化显示出null值的键值对
  • 原文地址:https://www.cnblogs.com/lin3615/p/3543546.html
Copyright © 2011-2022 走看看