simple dom parsing으로 로그인 후 파싱하기 질문입니다

simple dom parsing으로 로그인 후 파싱하기 질문입니다

QA

simple dom parsing으로 로그인 후 파싱하기 질문입니다

본문


/* login */
    $url = "http://xxxxxxxxxx.com/bbs/login_check.php"; 
    $cookie="cookie.txt"; 
    
    $data = array(
      "mb_id" => "test",
      "mb_password" => "1234"
    );
    
    $postData = http_build_query($data);
    
    $ch2 = curl_init();
    curl_setopt ($ch2, CURLOPT_URL, $url);
    curl_setopt ($ch2, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt ($ch2, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/3.0.0.13");
    curl_setopt ($ch2, CURLOPT_TIMEOUT, 60);
    curl_setopt ($ch2, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt ($ch2, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt ($ch2, CURLOPT_COOKIEJAR, $cookie); // respone되는 쿠키값을 저장함
    curl_setopt ($ch2, CURLOPT_COOKIEFILE, $cookie); // 저장한 쿠키값을 불러옴
    //curl_setopt ($ch2, CURLOPT_REFERER, $url);
    
    curl_setopt ($ch2, CURLOPT_POST, 2);
    curl_setopt ($ch2, CURLOPT_POSTFIELDS, $postData);
    $result2 = curl_exec ($ch2);
    
    echo $result2;  
    
    curl_close($ch2);
    
    
    for ($i=1;$i > 0;$i--) {
        $urls[] = array("src"=>"http://xxxxxxxx.com/bbs/board.php?bo_table=cheat_all&page={$i}","domain"=>"tolie.net", "target_bo_table"=>"free","category"=>"");
    }

 

그누보드 게시판이 로그인 후 볼 수 있는 게시판인데

위와같이 로그인 처리 한 후 url을 불러왔는데 로그인 처리가 되어있지 않아서 튕기는 문제가 있습니다.

 

로그인 해야만 볼 수 있는 게시판은 어떤식으로 파싱을 해야 하는지 궁금합니다.

이 질문에 댓글 쓰기 :

답변 3

1. 로그인할때는 쿠키 값 없이 로그인 

2. 1의 결과 인 result2 에서 쿠키값을 뽑아내서 cookie 에 저장

3. 2에서 추출된 cookie 를 다음에 url 호출할때 세팅후 호출



if(!function_exists('curl_login_with_cookie')){
    function curl_login_with_cookie($loginurl,array $account,$attempt=5){

        $parseURL = parse_url($loginurl);

        (G5_DATA_PATH.'/cookie', G5_DIR_PERMISSION);
        @chmod(G5_DATA_PATH.'/cookie', G5_DIR_PERMISSION);

        for ($i=1;$i<=$attempt;$i++){
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL,$loginurl);
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($account));
            curl_setopt($ch, CURLOPT_COOKIEJAR, G5_DATA_PATH.'/cookie/'.$parseURL['host'].".cookie");
            curl_setopt($ch, CURLOPT_USERAGENT,'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.52 Safari/537.17');


            ob_start();
            curl_exec ($ch);
            ob_end_clean();
            $err = curl_errno( $ch );
            $errmsg = curl_error( $ch );
            curl_close ($ch);

            if($errmsg==''){
                return $cookieFile =  G5_DATA_PATH.'/cookie/'.$parseURL['host'].".cookie";
            }
        }

        return false;


    }
}
if(!function_exists('curl_parse_with_cookie')){
    function curl_parse_with_cookie($url,$cookieFile='',$attempt=3){




        for ($i=1;$i<=$attempt;$i++){
            $ch = curl_init();

            if($cookieFile){
                curl_setopt($ch, CURLOPT_COOKIEFILE, $cookieFile);
            }


            curl_setopt($ch, CURLOPT_TIMEOUT,3);
            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

            curl_setopt($ch, CURLOPT_USERAGENT,'Googlebot-Image/1.0 Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)');
            curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
            curl_setopt($ch, CURLOPT_VERBOSE, 1);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
            curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);



            curl_setopt($ch, CURLOPT_URL,"$url");
            $result = curl_exec ($ch);
            $err = curl_errno( $ch );
            $errmsg = curl_error( $ch );
            curl_close ($ch);


            if($errmsg==''){
                return $result;
            }
        }


        return false;
    }
}

 

$url = "http://xxxxxxxxxx.com/bbs/login_check.php";    
$data = array(
    "mb_id" => "test",
    "mb_password" => "1234"
);


$cookie = curl_login_with_cookie(url,$data);


curl_parse_with_cookie('파싱주소',cookie );

글 게시물내에 불법 토토 관련 사이트 주소가 있네요..

답변을 작성하시기 전에 로그인 해주세요.
전체 123,592 | RSS
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT