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

来源:互联网 发布:linux cp参数个数 编辑:程序博客网 时间:2024/05/16 07:00

curl获取数据: index.php

$ch = curl_init();$url = 'http://www.lifangm.com/adobe/catalog_main.php';$header = array(    'cookie:*******');// 添加apikey到headercurl_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;

1 0
原创粉丝点击