스누피로 파싱되지 않는 사이트 긁어오는 방법 > php

본문 바로가기
사이트 내 전체검색

php

스누피로 파싱되지 않는 사이트 긁어오는 방법

페이지 정보

작성자 서방님 댓글 0건 조회 165회 작성일 16-10-11 11:46

본문

1. 세션을 물고 들어가야 하는 경우

 

스누피 fetch 하기전에 아래와 같이 세션값을 임의로 먹여준다.

$snoopy->cookies["SessionID"] = 세션값;

 

2. 자기 자신의 도메인으로 부터 들어오지 않으면 막아버리는 경우

 

위와 마찬가지로 fetch 하기전에 아래와 같이 값을 먹여준다.

$snoopy->referer = “접속한 도메인";

 

 

3. 외국 사이트가 한국 ip를 아예 차단한 경우

 

http://nntime.com/proxy-country/United-States-01.htm

www.cybersyndrome.net/plr5.html

 

위 사이트들에서 좋은 프록시 서버를 찾았으면 아래와 같이 세팅해준다.

$snoopy->proxy_host = “프록시서버"; 
$snoopy->proxy_port = "프록시 서버 포트번호";




네이버 카페에의 글 목록의 소스를 가져와서 파싱, 

iframe을 가져오는 방법.

 

 

<?
$szServer = "www.naver.com";
  $fp  = fsockopen($szServer, 80, $errorno, $errstr, 30);
  // Getting string
  $string = "";
  if(!$fp){
   echo "$errstr ($errno)<br>\n";
}else{
   fputs ($fp, "GET / HTTP/1.0\r\n\r\n");
 while(!feof($fp)) {
   $string .= fgets($fp, 128);
 }
 fclose($fp);
}
  echo "<textarea>$string</textarea>";
?>


헤더까지 받아오므로 헤더는 적절히 잘라주세요.


iframe의 src값을 받아오려면 받아온 $string을 적절하게 검색하시면 됩니다.


<?

$iFrameIndex = stripos($string, "<iframe");      if($iFrameIndex !== false){    $iFrameEndIndex = stripos($string, ">", $iFrameIndex);    $szFrame = substr($string, $iFrameIndex, $iFrameEndIndex - $iFrameIndex + 1);       $iSrcIndex = stripos($szFrame, "src");    $szFrame = substr($szFrame, $iSrcIndex+4);       if(substr($szFrame, 0, 1) == "\""){    $iSrcIndex = 1;    $iSrcEndIndex = stripos($szFrame, "\"", 1) - 1;    }else if(substr($szFrame, 4, 1) == "'"){    $iSrcIndex = 1;    $iSrcEndIndex = stripos($szFrame, "'", 1) - 1;    }else{    $iSrcIndex = 0;    $iSrcEndIndex = stripos($szFrame, " ", 1);    }       if($iSrcEndIndex === false){    $szFrame = substr($szFrame, $iSrcIndex);    }else{    $szFrame = substr($szFrame, $iSrcIndex, $iSrcEndIndex);    } } echo $szFrame;

?>


또한 받아온 iframe의 src의 내용을 받으실라면 src를 받은 $szFrame으로 소켓을 여시면됩니다.



댓글목록

등록된 댓글이 없습니다.

Total 612건 14 페이지
게시물 검색

회원로그인

접속자집계

오늘
109
어제
163
최대
1,347
전체
154,643
Latest Crypto Fear & Greed Index

그누보드5
Copyright © 서방님.kr All rights reserved.