zoukankan      html  css  js  c++  java
  • CURL的模拟登录和抓取页面

    <?php
    $curl = curl_init();// 初始化
    // 准备提交的表单数据之账号和密码。(这个是根据表单选项来的)
    $data = "_username=604989282@qq.com&_password=6481485" ;
    // 这个配置是为了防盗链,
    curl_setopt($curl,CURLOPT_REFERER,"http://www.ydma.cn/");
    // 基本配置
    curl_setopt($curl, CURLOPT_URL, 'http://www.ydma.cn/login/check');// 网址
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);// 不输出
    curl_setopt($curl, CURLOPT_POST, 1);// POST方式
    curl_setopt($curl, CURLOPT_POSTFIELDS,$data);// POST数据
    curl_setopt($curl, CURLOPT_HTTPHEADER, array(// 头部信息类型
      "content-type: application/x-www-form-urlencoded",
    ));
    
    // Cookie相关设置
    date_default_timezone_set("PRC");
    curl_setopt($curl,CURLOPT_COOKIESESSION,TRUE);// 开启cookie和session
    curl_setopt($curl,CURLOPT_COOKIEFILE,"cookiefile");// 存储名称
    curl_setopt($curl,CURLOPT_COOKIEJAR,"cookiefile");// 存储名称
    curl_setopt($curl,CURLOPT_COOKIE,session_name()."=".session_id());// 存储的是session_name()和session_id()
    
    curl_setopt($curl,CURLOPT_FOLLOWLOCATION,1);// 设置可以跳转
    curl_setopt($curl,CURLOPT_HEADER,0);// 不去打印头部信息
    
    curl_setopt($curl,CURLOPT_REFERER,"http://www.ydma.cn/");
    
    
    
    // 设置一下跳转页面
    // curl_setopt($curl,CURLOPT_URL,"http://www.ydma.cn/user/52897/learn");
    curl_setopt($curl,CURLOPT_URL,"http://www.ydma.cn/course/137/preview/lesson/3961");
      
    curl_setopt($curl,CURLOPT_POST,0);
    
    curl_setopt($curl,CURLOPT_HTTPHEADER,array("Content-type:text/html"));
    
    curl_setopt($curl,CURLOPT_REFERER,"http://www.ydma.cn/");
    
    $res = curl_exec($curl);
    
    curl_close($curl);
    
    // echo str_replace('src="/files', 'src="http://www.ydma.cn/files', $res);
    
    // echo substr_replace($res,"<base href='http://www.ydma.cn/'>",strpos("<head>",$res),0);
    echo str_replace("<head>","<head><base href='http://www.ydma.cn/'>",$res);
    // echo $res;

    页面来源:https://www.jianshu.com/p/682ddef25f55

    测试一个网站,因为需要验证码没获取到信息

  • 相关阅读:
    jsonp 监控简陋代码
    Oracle多线程并行使用、关联与指定索引执行
    Oracle计算时间差表达式
    行查列显
    JS时间
    通过string型类名实例化一个类
    sotower1.5-LS_工作流容易出错的地方
    oracle11g ORA-12505
    华项笔记本显示颜色变黄,调整好了重启还是偏黄
    ORA-00031: session marked for kill 处理Oracle中杀不掉的锁
  • 原文地址:https://www.cnblogs.com/init-007/p/11041980.html
Copyright © 2011-2022 走看看