본문 바로가기

Computer/Programing

Snoopy 이용법해서 파싱 방법



아래에서 파일을 다운받아서 압축을 풀고 Snoopy.class.php 파일만 실행될 파일과 동일한 디렉토리에 넣어주면 작동한다.

https://sourceforge.net/projects/snoopy/files/latest/download


<?php

include_once 'Snoopy.class.php';

$snoopy = new snoopy;


// 웹브라우져에서 검색하는것처럼 위장

$snoopy->agent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";

$snoopy->referer = "http://target.com/";   


$snoopy->fetch("http://www.example.com");

$txt = $snoopy->results;

echo $txt;

//배열함수일경우 print_r($txt);

?>






<?php

include_once 'Snoopy.class.php';

$snoopy = new snoopy;


 // 접속경로 표기

$snoopy->agent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";

$snoopy->referer = "http://target.com/";


 // parsing 실행

$snoopy->fetch("http://target.com");


 // parsing 실행한 자료를 txt 함수에 저장

$txt = $snoopy->results;


// amp 를 공백으로 변환

$removeamp = str_replace("amp;","",$txt);


// $removeamp 에서 'href="./view_magnifying.jsp?' 을 기준으로 앞뒤로  나눔

$addr1 = @explode('href="./view_magnifying.jsp?', $removeamp);

$addr2 = @explode('" onclick="magnifyViewAction(this.href);return false;"', $addr1[1]);


// 배열함수 $addr2[0] 을 출력, 

print_r($addr2[0]);


// 함수에  기본주소와 분리된 주소를 통합, ( "."점을 사용해서 통합)

$addr ="http://ya-ho/modules/cafe/class/menu/board/view_magnifying.jsp??".$addr2[0];


// 함수 $addr 출력

echo $addr;

 

// html3[0] 함수에 줄바꿈 \r\n 을 추가함.

$html3a = $html3[0]."\r\n";


// euckr 문자를 utf8로 변경

$title = iconv("euckr","utf8",$html3a);

$html4 = iconv("euckr","utf8",$html3[1]);


// url을 인코딩

$titleurl = urlencode($title);


// 기타

$html4 = strip_tags($html3[1]);

$html5 = preg_replace("/\s\s+/","",$html4);

$html6 = str_replace("<div class=\"content\">","",$html5);

$breaks = array("<br />","</b>");

$html7 = str_ireplace($breaks,"\r\n",$html6);


?>


If 함수

for ($i = 130; $i >= 0; $i--) {                                                                                                                              

if (strpos($html[$i],"view") !== false) {                                                                                                                    

//echo $html[$i]."\r\n"; }


}

}


//찾아서 배열(array) 함수 match 에 저장

preg_match_all("'\/board\/view.php\?table=bestofbest((.*\n){7})'i",$html,$match);



// 배열함수를 함수로 변경 array to string

$string = $array[1];