테스트 사이트 - 개발 중인 베타 버전입니다

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

지솩 5년 전 조회 3,079

</p>

<p>/* login */

    $url = "<a href="http://xxxxxxxxxx.com/bbs/login_check.php"; " target="_blank" rel="noopener noreferrer">http://xxxxxxxxxx.com/bbs/login_check.php"; </a>

    $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"=>"<a href="http://xxxxxxxx.com/bbs/board.php?bo_table=cheat_all&page={$i}","domain"=>"tolie.net"," target="_blank" rel="noopener noreferrer">http://xxxxxxxx.com/bbs/board.php?bo_table=cheat_all&page={$i}","domain"=>"tolie.net",</a> "target_bo_table"=>"free","category"=>"");

    }</p>

<p>

 

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

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

 

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

댓글을 작성하려면 로그인이 필요합니다.

답변 3개

채택된 답변
+20 포인트
5년 전

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

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

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

로그인 후 평가할 수 있습니다

답변에 대한 댓글 3개

지솩
5년 전
답변감사합니다. 어렵네요 ㅠㅠ 혹시 관련정보를 얻으려면 키워드를 뭐라고 쳐서 검색 해야 하나요?
백수1995
5년 전
curl 을 이용한 웹 크롤링, 웹 로그인?
지솩
5년 전
감사합니다. 많은 도움 되었습니다.

댓글을 작성하려면 로그인이 필요합니다.

T
5년 전

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

로그인 후 평가할 수 있습니다

답변에 대한 댓글 2개

지솩
5년 전
아 저사이트는 불법사이트가 아닙니다. 더치트와 비슷한 사이트이며 로그인 후 데이터를 가져오는 방식을 구현하고자 하는것입니다.
S
Swiss
5년 전
불법 도박 사이트 광고가 달려 있는 불법 도박사이트 검증 사이트를
어떤 관점에서 보면 불법이 아닌가요?

댓글을 작성하려면 로그인이 필요합니다.

세크티
5년 전

</p>

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

        $parseURL = parse_url($loginurl);

        @mkdir(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; +<a href="http://www.google.com/bot.html)');" target="_blank" rel="noopener noreferrer">http://www.google.com/bot.html)');</a>
            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;
    }
}</pre>

<p> </p>

<pre>
<code>$url = "<a href="http://xxxxxxxxxx.com/bbs/login_check.php";" target="_blank" rel="noopener noreferrer">http://xxxxxxxxxx.com/bbs/login_check.php";</a>    
$data = array(
    "mb_id" => "test",
    "mb_password" => "1234"
);</code></pre>

<pre>
<code>$cookie = </code>curl_login_with_cookie(<code>url,$data</code>);</pre>

<pre>
curl_parse_with_cookie('파싱주소',<code>cookie </code>);</pre>

<p>

로그인 후 평가할 수 있습니다

댓글을 작성하려면 로그인이 필요합니다.

답변을 작성하려면 로그인이 필요합니다.

로그인