zoukankan      html  css  js  c++  java
  • curl抓取信息

    <?php
        $hotel = new curl(false,0);
        $str = $hotel -> post("http://www.todayinns.com/login.php?do=login",array("Referer"=>"","username"=>"18612690317","password"=>"2010"))->execute();
        echo $hotel -> get("http://www.todayinns.com/my_jf.php")->execute();;
        
        
    /**
     * 一个基础的CURL类
     *
     * @author Smala
     */
        class curl{
            public $ch;
            public $cookie = '/cookie';            
            public $rstr;                                
            public $info;                                
            
            public function __construct($ssl=true,$cookieName="tmp.cookie"){
             
                
                $this -> cookie = dirname(__FILE__)."/".$cookieName;
                $this -> ch = curl_init();
                curl_setopt($this -> ch ,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.36');//设置用户代理
                curl_setopt($this -> ch,CURLOPT_COOKIEJAR,$this -> cookie);        
                curl_setopt($this -> ch,CURLOPT_COOKIEFILE,$this -> cookie);    
                
                if($ssl){
                    curl_setopt($this -> ch, CURLOPT_SSL_VERIFYPEER, false);
                    curl_setopt($this -> ch, CURLOPT_SSL_VERIFYHOST, false);
                }
                curl_setopt($this -> ch,CURLOPT_RETURNTRANSFER,1);
            }
            
            public function set($opt){
                foreach($opt as $key => $value)
                curl_setopt($this -> ch,$key,$value);
                return $this;
            }
            public function get($url,$data=array()){
                $queryString = http_build_query($data);
                if(!empty($queryString)){
                    $url.= '?'.$queryString;
                }
                curl_setopt($this -> ch,CURLOPT_URL,$url);
                return $this;
                
            }
            public function setHeader($data=array()){
                curl_setopt($this -> ch,CURLOPT_HTTPHEADER,$data);
                return $this;
            }
            public function post($url,$data = array()){
                $post = '';
                foreach($data as $key=>$value){
                    $post .= $key.'='.$value."&";
                    
                }
                $post = trim($post,'&');
                curl_setopt($this -> ch,CURLOPT_URL,$url);
                curl_setopt($this -> ch,CURLOPT_POST,1);        
                curl_setopt($this -> ch,CURLOPT_POSTFIELDS,$post);    
                return $this;
            }
            public function execute($close=true){
                
                $this -> rstr = curl_exec($this -> ch);
                $this -> info = curl_getinfo($this -> ch);
                if($close){
                   // curl_close($this -> ch);
                }
                return $this -> rstr;
                
            }
            public function close(){
                curl_close($this -> ch);
            }
            
        }
    $hotel = new curl(false,0);
    $str = $hotel -> post("http://www.todayinns.com/login.php?do=login",array("Referer"=>"","username"=>$_COOKIE['the_tel'],"password"=>$_COOKIE['password']))->execute();
    $arrs = $hotel -> get("http://www.todayinns.com/my_ticket.php")->execute();
    preg_match_all('/<dd class="c">(.*?)</dd>/is',$arrs,$tmp);
    preg_match_all( '/<tr[^>]*([sS]*?)</tr>/i', $tmp[1][0], $arr );
    preg_match_all( '/<td>(.*?)</td>/i', $arr[1][1], $volume );
  • 相关阅读:
    Caffe学习系列(18): 绘制网络模型
    Caffe学习系列(17):模型各层数据和参数可视化
    android ------ RecyclerView 模仿淘宝购物车
    android ------- 开发者的 RxJava 详解
    android -------- 压缩图片文件工具类
    android -------- MVP+DataBinding 的使用
    android -------- ConstraintLayout Group和goneMargin(五)
    android -------- ConstraintLayout Guideline和Barrier(四)
    android -------- ConstraintLayout 宽高比和偏移量比(三)
    android -------- ConstraintLayout 约束属性(二)
  • 原文地址:https://www.cnblogs.com/phpfensi/p/3910783.html
Copyright © 2011-2022 走看看