已知cookie的情况下,curl模拟请求并获取后台内容

    xiaoxiao2021-04-18  65

    curl获取数据: index.php

    $ch = curl_init(); $url = 'http://www.lifangm.com/adobe/catalog_main.php'; $header = array( 'cookie:*******' ); // 添加apikey到header curl_setopt($ch, CURLOPT_HTTPHEADER , $header); //curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:50.0) Firefox/50.0'); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_AUTOREFERER, 1); // 执行HTTP请求 curl_setopt($ch , CURLOPT_URL , $url); $res = curl_exec($ch); curl_close($ch); 抓取数据并保存:ser.php

    $url="http://localhost/indexs.php"; $str=file_get_contents($url); //echo $str; $reg = "#<a\s*\S*\s*oncontextmenu[^>]*>(<font[^>]*>\S*<\/font>)?([^\[]*)\[ID:(\d+)\]#isU"; preg_match_all($reg,$str,$arr); unset($arr[0]); foreach ($arr[1] as $k => $r) { $array[] = array($arr[1][$k],$arr[2][$k],$arr[3][$k]); } var_dump($array);die;

    转载请注明原文地址: https://ju.6miu.com/read-675311.html

    最新回复(0)