当前位置 : 主页 > 网络编程 > PHP >

php采集51job简历示例代码

来源:互联网 收集:自由互联 发布时间:2021-06-28
import51JobResumeList.php _getAllParam(); set_time_limit(300); header("Content-type: text/html; charset=utf-8"); $useragent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.81 Safari/537.36"; if
import51JobResumeList.php
 _getAllParam();
    set_time_limit(300);
    header("Content-type: text/html; charset=utf-8");
    $useragent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.81 Safari/537.36";
    if(empty($params['user_name'])||empty($params['password'])){
        $this->ajaxFailed(500, '帐号名或密码不能为空');
//            $user_name=$params['user_name']='raodeming@37.com1';
//            $password=$params['password']='www.37.com';
//            $ver_code=$params['ver_code']; //  验证码
    }else{
        $user_name=$params['user_name'];
        $password=$params['password'];
        $ver_code=$params['ver_code']; //  验证码
    }
    $username = urlencode($user_name);
    $userpwd = urlencode($password);
    $ver_code = urlencode($ver_code);
    $refer="http://51job.com/";
    $login_url = JOB51_LOGIN_URL;//登录页地址
    $get_url = JOB51_GET_URL; //My51job
    //用户名和密码
    if(empty($ver_code)){
        $post_fields = "from_domain=www.51job.com&passport_loginName={$username}&passport_password={$userpwd}";
    }else{
        $post_fields = "from_domain=www.51job.com&passport_loginName={$username}&passport_password={$userpwd}&passport_verify={$ver_code}";
    }
    //首先登陆并得到cookie
    if(!isset($_SESSION['cookie_file_51'])){
        $cookie_file = tempnam (CURL_COOKIE_DIR, "cookie");
        $_SESSION['cookie_file_51']=$cookie_file;
    }
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $login_url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch,CURLOPT_REFERER,$refer);
    curl_setopt($ch, CURLOPT_COOKIEFILE, $_SESSION['cookie_file_51']);
    curl_setopt($ch, CURLOPT_COOKIEJAR, $_SESSION['cookie_file_51']); //保存cookie  登录后的cookie
    curl_setopt($ch, CURLOPT_USERAGENT, $useragent );
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields);
    curl_setopt($ch, CURLOPT_TIMEOUT, 15);
    $login_content = curl_exec($ch);
    curl_close($ch);

    //判断登录是否成功
    $res = json_decode(trim(strrchr($login_content,"		")),true);
    if(!$res['result']){
        if($res['status']=="-3"){  //  此状态要返回验证码
            if( ENVIRONMENT == 'development' ){
                $ver_code_name="http://local.zhaopin.i37wan.net/index.php?c=mobile_job&a=ver_code51";
            }else{
                $ver_code_name="http://zhaopin.37.com/index.php?c=mobile_job&a=ver_code51";
            }
            $this->ajaxSuccessMsg(301,array('ver_code'=>$ver_code_name),"验证码错误");

        }else{
            $this->ajaxFailed(500,"帐号或密码错误");
        }
        /*echo "
 
 
";*/ } //获取我的简历地址 $header = ''; $content = ''; $http_code = $this->_curl_get_url($get_url,$_SESSION['cookie_file_51'],$login_url,$header,$content, 15); //查找“我的简历“地址 //“我的简历“地址正则 $resume_manage_url_reg = JOB51_RESUME_URL_REG; if($content && preg_match($resume_manage_url_reg,$content,$matches)){ $resume_manage_url = $matches[1]; } if(empty($resume_manage_url)){ $this->ajaxFailed(500,'未获取到简历地址'); } //获取用户简历 $header = ''; $resume_list = ""; $http_code = $this->_curl_get_url($resume_manage_url,$_SESSION['cookie_file_51'],$get_url,$header,$resume_list,15); $resume_arr = array(); if(!empty($resume_list)){ $html = new simple_html_dom(); $html->load($resume_list); $tr_res = $html->find('.resumeList table', 0)->find('tr.resumeName'); if (is_array($tr_res)) { foreach ($tr_res as $one) { $ResumeName = $one->find('td', 0)->find('a', 0)->innertext; $ResumeUrl = $one->find('td', 8)->find('a', 0)->href; $complete_str=$one->innertext; preg_match('/ .*?</div>/',$complete_str,$complete_arr); $complete_precent=ceil($complete_arr[1]*1.25)."%"; $resume_arr[] = array('resume_name' => $ResumeName, 'resume_url' => $ResumeUrl,'complete_precent'=>$complete_precent); } } } $this->ajaxSuccess(200,array('resume_info'=>$resume_arr)); }
网友评论