zoukankan      html  css  js  c++  java
  • php querylist 抓取需要cookie验证的接口数据

    具体是某某品台 不多说

    上代码

    主要是要注意不停地调试 找到需要的cookie

    具体URL打马赛克   host referer和Origin也是直接抄袭浏览器的即可

    主要是通过

    $jar = new CookieJar();来存储已经获取到的cookie然后代入下一个方法进行访问

    然后 有的request的类型是json的 必须使用
    postJson 方法
        /*---------------------------------社会****平台 403----------------------------------------------*/
        public function get_chinanpo_links($page=1,$number=10)
        {
            $url = "https://******.cn/****";
           $url0 = "https://******.cn/****";
           $url1= "https://******.cn/****";
           $url2 = "https://******.cn/****";
           $url3 = "https://******.cn/****";
            echo "<pre>";
            $jar = new CookieJar();
    
            //第一步 获取到get中返回的cookie   
           // Cache::set('jar', null);
    
            if (!Cache::get('jar')) {
                $ql = QueryList::get($url, [], ['cookies' => $jar]);
                $jar_128 = $jar;
                $ql = QueryList::post($url0, [], ['cookies' => $jar]);
    
                Cache::set('jar', $jar);
            } else {
                $jar = Cache::get('jar');
            }
            $cookieArr = $jar->toArray();
            print_r($cookieArr);
    
            $params1 = [
                'headers' => [
                    'Accept' => 'application/json, text/plain, */*',
                    'Accept-Encoding' => 'gzip, deflate, br',
                    'Cookie' => $cookieArr[0]['Name'] . "=" . $cookieArr[0]['Value'] . "; " . $cookieArr[1]['Name'] . "=" . $cookieArr[1]['Value'],
                    'Accept-Language' => 'zh-CN,zh;q=0.9,en;q=0.8',
                    'Connection' => 'keep-alive',
                    'Content-Length' => 0,
                    'Host' => '******',
                    'Origin' => '******',
                    'Referer' => '******', //不能去掉
                    'Sec-Fetch-Dest' => 'empty',
                    'Sec-Fetch-Mode' => 'cors',
                    'Sec-Fetch-Site' => 'same-origin',
                    'User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'
                ]
            ];
    
            $params2 = [
                //'cookie'=>$jar,
                'headers' => [
                    'Accept' => 'application/json, text/plain, */*',
                    'Accept-Encoding' => 'gzip, deflate, br',
                    'Accept-Language' => 'zh-CN,zh;q=0.9,en;q=0.8',
                    'Connection' => 'keep-alive',
                    'Content-Length' => 26,
                    'Content-Type'=> 'application/json;charset=UTF-8',
                    'Cookie' => $cookieArr[0]['Name'] . "=" . $cookieArr[0]['Value'] . "; " . $cookieArr[1]['Name'] . "=" . $cookieArr[1]['Value'],
                            'Host' => '******',
                    'Origin' => '******',
                    'Referer' => '******', //不能去掉
                    'Sec-Fetch-Dest' => 'empty',
                    'Sec-Fetch-Mode' => 'cors',
                    'Sec-Fetch-Site' => 'same-origin',
                    'User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'
                ]
            ];
    
            $params3 = [
                //'cookie'=>$jar,
                'headers' => [
                    'Accept' => 'application/json, text/plain, */*',
                    'Accept-Encoding' => 'gzip, deflate, br',
                    'Accept-Language' => 'zh-CN,zh;q=0.9,en;q=0.8',
                    'Connection' => 'keep-alive',
                    'Content-Length' => 15,
                    'Content-Type'=> 'application/json;charset=UTF-8',
                    'Cookie' => $cookieArr[0]['Name'] . "=" . $cookieArr[0]['Value'] . "; " . $cookieArr[1]['Name'] . "=" . $cookieArr[1]['Value'],
                    'Host' => '******',
                    'Origin' => '******',
                    'Referer' => '******', //不能去掉
                    'Sec-Fetch-Dest' => 'empty',
                    'Sec-Fetch-Mode' => 'cors',
                    'Sec-Fetch-Site' => 'same-origin',
                    'User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'
                ]
            ];
    
            print_r($params2);
    
    //        try {
    //            $ql = QueryList::post($url1, [], $params1);
    //        } catch (ClientException  $e) {
    //            echo "<pre>";
    //            echo $e->getRequest();
    //            echo $e->getResponse();
    //            exit();
    //        }
    
    
    
            try {
                $ql = QueryList::postJson($url2, ['pageNo'=>$page,'pageSize'=>$number], $params2);
            } catch (ClientException  $e) {
                echo "<pre>";
                echo $e->getRequest();
                echo $e->getResponse();
                exit();
            }
    
    //
    //                try {
    //            $ql = QueryList::post($url3, ['id'=>"000000"], $params3);
    //        } catch (ClientException  $e) {
    //            echo "<pre>";
    //            echo $e->getRequest();
    //            echo $e->getResponse();
    //            exit();
    //        }
    
            print_r(json_decode($ql->getHtml()));
            exit();
    
    
        }
    

      

    你不能把坏习惯扔出窗外 但你可以一步步赶下电梯
  • 相关阅读:
    android有点纠结的小问题
    持久化应用程序实例的状态
    preference activity框架
    RISC与CISC比较
    C++ const用法
    虚析构函数
    best-case analysis in real-time system
    jitter
    C/C++中static,const,inline三种关键字详细总结
    #pragma warning(disable 4786)
  • 原文地址:https://www.cnblogs.com/Ychao/p/14641460.html
Copyright © 2011-2022 走看看